Problem: How to convert a text value into an encrypted value?
There are
cryptographic functions which support encryption, decryption, digital signing
and the validation of digital signing.
Among these
functions encryption hashing is done by the function Hashbytes.
Syntax:
HASHBYTES
(‘<algorithm>', {@input | 'input’})
<algorithm>::=
MD2 | MD4 | MD5 | SHA | SHA1 | SHA2_256 | SHA2_512
MD2, MD4,
MD5, SHA, SHA1 are 128-bit value encryption.
SHA2_256
is a 256-bit value encryption
SHA2_512
is a 512-bit value encryption
This value
encryption is used to compare the text of password or sensitive text.
Example:
In this
Example, I would like to show how we can convert a text value into a 128-bit
encryption value.
DECLARE @UserPassword nvarchar(4000),@inputpassword
nvarchar(4000);
SET @UserPassword = 'P@$$w0rd';
SELECT HASHBYTES('SHA1', @UserPassword);
SET @inputpassword = 'p@$$word';
SELECT HASHBYTES('SHA1', @inputpassword);
IF(@UserPassword=@inputpassword)
BEGIN
SELECT 'Password
entered is correct: Login Successful' as
OUTPUT
END
IF(@UserPassword<>@inputpassword)
BEGIN
SELECT 'Password
entered is incorrect: Login Un-Successful' as
OUTPUT
END
OUTPUT:
OUTPUT
|
Password
entered is incorrect: Login Un-Successful
|
0 comments:
Post a Comment