Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. create function [dbo].[security_GetPasswordHash]
  2. (
  3. @Password sysname,
  4. @Salt uniqueidentifier
  5. )
  6.  
  7. returns binary(128) with schemabinding, returns null on null input as begin
  8.  
  9. declare @CertId int, @CertPwd sysname;
  10.  
  11. set @CertId = ...; -- Get your cert however you like it
  12. set @CertPwd = ...; -- If your cert is encrypted with password, get it too
  13.  
  14. return SignByCert(
  15. @CertId,
  16. SignByCert(@CertId, @Password, @CertPwd) + cast(@Salt as binary(16)),
  17. @CertPwd
  18. );
  19. end;
  20. go
  21.  
  22. -- Try to validate the user
  23. select @UserId = u.Id
  24. from dbo.Users u
  25. where u.LoginName = @Login
  26. and u.PasswordHash = dbo.security_GetPasswordHash(@Password, u.PasswordSalt);
  27.  
  28. -- Special case of user existence - there may be a wrong password here, too.
  29. if @UserId is null begin
  30. -- The specified user either does not exist, or wrong password has been supplied.
  31. set @Error = 51008;
  32. set @Message = dbo.sys_FormatErrorMessage(@Error, @CultureId, default, default, default, default);
  33. throw 50000, @Message, 1;
  34. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement