mirror of
https://github.com/bitwarden/server.git
synced 2024-12-03 14:03:33 +01:00
248 lines
5.6 KiB
Transact-SQL
248 lines
5.6 KiB
Transact-SQL
IF COL_LENGTH('[dbo].[User]', 'Kdf') IS NULL
|
|
BEGIN
|
|
ALTER TABLE
|
|
[dbo].[User]
|
|
ADD
|
|
[Kdf] TINYINT NULL,
|
|
[KdfIterations] INT NULL
|
|
END
|
|
GO
|
|
|
|
UPDATE
|
|
[dbo].[User]
|
|
SET
|
|
[Kdf] = 0,
|
|
[KdfIterations] = 5000
|
|
GO
|
|
|
|
ALTER TABLE
|
|
[dbo].[User]
|
|
ALTER COLUMN
|
|
[Kdf] TINYINT NOT NULL
|
|
GO
|
|
|
|
ALTER TABLE
|
|
[dbo].[User]
|
|
ALTER COLUMN
|
|
[KdfIterations] INT NOT NULL
|
|
GO
|
|
|
|
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView')
|
|
BEGIN
|
|
DROP VIEW [dbo].[UserView]
|
|
END
|
|
GO
|
|
|
|
CREATE VIEW [dbo].[UserView]
|
|
AS
|
|
SELECT
|
|
*
|
|
FROM
|
|
[dbo].[User]
|
|
GO
|
|
|
|
IF OBJECT_ID('[dbo].[User_Create]') IS NOT NULL
|
|
BEGIN
|
|
DROP PROCEDURE [dbo].[User_Create]
|
|
END
|
|
GO
|
|
|
|
CREATE PROCEDURE [dbo].[User_Create]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(50),
|
|
@Email NVARCHAR(50),
|
|
@EmailVerified BIT,
|
|
@MasterPassword NVARCHAR(300),
|
|
@MasterPasswordHint NVARCHAR(50),
|
|
@Culture NVARCHAR(10),
|
|
@SecurityStamp NVARCHAR(50),
|
|
@TwoFactorProviders NVARCHAR(MAX),
|
|
@TwoFactorRecoveryCode NVARCHAR(32),
|
|
@EquivalentDomains NVARCHAR(MAX),
|
|
@ExcludedGlobalEquivalentDomains NVARCHAR(MAX),
|
|
@AccountRevisionDate DATETIME2(7),
|
|
@Key NVARCHAR(MAX),
|
|
@PublicKey NVARCHAR(MAX),
|
|
@PrivateKey NVARCHAR(MAX),
|
|
@Premium BIT,
|
|
@PremiumExpirationDate DATETIME2(7),
|
|
@RenewalReminderDate DATETIME2(7),
|
|
@Storage BIGINT,
|
|
@MaxStorageGb SMALLINT,
|
|
@Gateway TINYINT,
|
|
@GatewayCustomerId VARCHAR(50),
|
|
@GatewaySubscriptionId VARCHAR(50),
|
|
@LicenseKey VARCHAR(100),
|
|
@Kdf TINYINT,
|
|
@KdfIterations INT,
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7)
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
INSERT INTO [dbo].[User]
|
|
(
|
|
[Id],
|
|
[Name],
|
|
[Email],
|
|
[EmailVerified],
|
|
[MasterPassword],
|
|
[MasterPasswordHint],
|
|
[Culture],
|
|
[SecurityStamp],
|
|
[TwoFactorProviders],
|
|
[TwoFactorRecoveryCode],
|
|
[EquivalentDomains],
|
|
[ExcludedGlobalEquivalentDomains],
|
|
[AccountRevisionDate],
|
|
[Key],
|
|
[PublicKey],
|
|
[PrivateKey],
|
|
[Premium],
|
|
[PremiumExpirationDate],
|
|
[RenewalReminderDate],
|
|
[Storage],
|
|
[MaxStorageGb],
|
|
[Gateway],
|
|
[GatewayCustomerId],
|
|
[GatewaySubscriptionId],
|
|
[LicenseKey],
|
|
[Kdf],
|
|
[KdfIterations],
|
|
[CreationDate],
|
|
[RevisionDate]
|
|
)
|
|
VALUES
|
|
(
|
|
@Id,
|
|
@Name,
|
|
@Email,
|
|
@EmailVerified,
|
|
@MasterPassword,
|
|
@MasterPasswordHint,
|
|
@Culture,
|
|
@SecurityStamp,
|
|
@TwoFactorProviders,
|
|
@TwoFactorRecoveryCode,
|
|
@EquivalentDomains,
|
|
@ExcludedGlobalEquivalentDomains,
|
|
@AccountRevisionDate,
|
|
@Key,
|
|
@PublicKey,
|
|
@PrivateKey,
|
|
@Premium,
|
|
@PremiumExpirationDate,
|
|
@RenewalReminderDate,
|
|
@Storage,
|
|
@MaxStorageGb,
|
|
@Gateway,
|
|
@GatewayCustomerId,
|
|
@GatewaySubscriptionId,
|
|
@LicenseKey,
|
|
@Kdf,
|
|
@KdfIterations,
|
|
@CreationDate,
|
|
@RevisionDate
|
|
)
|
|
END
|
|
GO
|
|
|
|
IF OBJECT_ID('[dbo].[User_Update]') IS NOT NULL
|
|
BEGIN
|
|
DROP PROCEDURE [dbo].[User_Update]
|
|
END
|
|
GO
|
|
|
|
CREATE PROCEDURE [dbo].[User_Update]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(50),
|
|
@Email NVARCHAR(50),
|
|
@EmailVerified BIT,
|
|
@MasterPassword NVARCHAR(300),
|
|
@MasterPasswordHint NVARCHAR(50),
|
|
@Culture NVARCHAR(10),
|
|
@SecurityStamp NVARCHAR(50),
|
|
@TwoFactorProviders NVARCHAR(MAX),
|
|
@TwoFactorRecoveryCode NVARCHAR(32),
|
|
@EquivalentDomains NVARCHAR(MAX),
|
|
@ExcludedGlobalEquivalentDomains NVARCHAR(MAX),
|
|
@AccountRevisionDate DATETIME2(7),
|
|
@Key NVARCHAR(MAX),
|
|
@PublicKey NVARCHAR(MAX),
|
|
@PrivateKey NVARCHAR(MAX),
|
|
@Premium BIT,
|
|
@PremiumExpirationDate DATETIME2(7),
|
|
@RenewalReminderDate DATETIME2(7),
|
|
@Storage BIGINT,
|
|
@MaxStorageGb SMALLINT,
|
|
@Gateway TINYINT,
|
|
@GatewayCustomerId VARCHAR(50),
|
|
@GatewaySubscriptionId VARCHAR(50),
|
|
@LicenseKey VARCHAR(100),
|
|
@Kdf TINYINT,
|
|
@KdfIterations INT,
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7)
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
UPDATE
|
|
[dbo].[User]
|
|
SET
|
|
[Name] = @Name,
|
|
[Email] = @Email,
|
|
[EmailVerified] = @EmailVerified,
|
|
[MasterPassword] = @MasterPassword,
|
|
[MasterPasswordHint] = @MasterPasswordHint,
|
|
[Culture] = @Culture,
|
|
[SecurityStamp] = @SecurityStamp,
|
|
[TwoFactorProviders] = @TwoFactorProviders,
|
|
[TwoFactorRecoveryCode] = @TwoFactorRecoveryCode,
|
|
[EquivalentDomains] = @EquivalentDomains,
|
|
[ExcludedGlobalEquivalentDomains] = @ExcludedGlobalEquivalentDomains,
|
|
[AccountRevisionDate] = @AccountRevisionDate,
|
|
[Key] = @Key,
|
|
[PublicKey] = @PublicKey,
|
|
[PrivateKey] = @PrivateKey,
|
|
[Premium] = @Premium,
|
|
[PremiumExpirationDate] = @PremiumExpirationDate,
|
|
[RenewalReminderDate] = @RenewalReminderDate,
|
|
[Storage] = @Storage,
|
|
[MaxStorageGb] = @MaxStorageGb,
|
|
[Gateway] = @Gateway,
|
|
[GatewayCustomerId] = @GatewayCustomerId,
|
|
[GatewaySubscriptionId] = @GatewaySubscriptionId,
|
|
[LicenseKey] = @LicenseKey,
|
|
[Kdf] = @Kdf,
|
|
[KdfIterations] = @KdfIterations,
|
|
[CreationDate] = @CreationDate,
|
|
[RevisionDate] = @RevisionDate
|
|
WHERE
|
|
[Id] = @Id
|
|
END
|
|
GO
|
|
|
|
IF OBJECT_ID('[dbo].[User_ReadKdfByEmail]') IS NOT NULL
|
|
BEGIN
|
|
DROP PROCEDURE [dbo].[User_ReadKdfByEmail]
|
|
END
|
|
GO
|
|
|
|
CREATE PROCEDURE [dbo].[User_ReadKdfByEmail]
|
|
@Email NVARCHAR(50)
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
SELECT
|
|
[Kdf],
|
|
[KdfIterations]
|
|
FROM
|
|
[dbo].[User]
|
|
WHERE
|
|
[Email] = @Email
|
|
END
|
|
GO
|