Skip to content

Instantly share code, notes, and snippets.

@amarkulo
Last active July 20, 2021 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amarkulo/9977c9807ce5bfb1fe968543f62f9cf6 to your computer and use it in GitHub Desktop.
Save amarkulo/9977c9807ce5bfb1fe968543f62f9cf6 to your computer and use it in GitHub Desktop.
Import data to PwnedPwdDB
-- create table
USE [PwnedPwdDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BadHashes](
[hash_id] [int] IDENTITY(1,1) NOT NULL,
[hash] [varchar](40) NOT NULL,
CONSTRAINT [Hashes_PK] PRIMARY KEY CLUSTERED
(
[hash_id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
-- add index
CREATE UNIQUE NONCLUSTERED INDEX [Hashes_Sorted_Index] ON [dbo].[BadHashes]
(
[hash] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = ON, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
-- create view
CREATE VIEW [dbo].[Hashes]
AS
SELECT hash
FROM dbo.BadHashes
GO
-- create user
USE [master]
GO
CREATE LOGIN [pwndbreader] WITH PASSWORD=N'pwndbreaderpassword', DEFAULT_DATABASE=[PwnedPwdDB], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [PwnedPwdDB]
GO
CREATE USER [pwndbreader] FOR LOGIN [pwndbreader]
GO
USE [PwnedPwdDB]
GO
ALTER USER [pwndbreader] WITH DEFAULT_SCHEMA=[db_datareader]
GO
USE [PwnedPwdDB]
GO
ALTER ROLE [db_datareader] ADD MEMBER [pwndbreader]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment