If you are interested in MSSQL user information, you may find the master. dbo. sysxlogins stores user passwords. However, if the password field is not null, It is a bunch of binary files that cannot be understood. How is this password encrypted?
In fact, you only need to take a closer look at master. dbo. sp_addlogin and you will be able to see the code in the MSSQL sp.
Let's take a look at how it works. Pay attention to this line of select @ passwd = pwdencrypt (@ passwd). After this, @ passwd will be encrypted. Let's also try it.
DECLARE @ ClearPWD varchar (255)
DECLARE @ EncryptedPWD varbinary (255)
SELECT @ ClearPWD = 'test'
SELECT @ EncryptedPWD = CONVERT (varbinary (255), pwdencrypt (@ ClearPWD ))
SELECT @ EncryptedPWD
It looks good. It is indeed encrypted, but how can I restore it?
Password Encryption is one-way. You can use encrypted passwords to compare them.
Continue to look at the sp related to other users. You can find that the master. dbo. sp_password contains the password comparison content.
Pwdcompare (@ old, password, (case when xstatus & 2048 = 2048 THEN 1 ELSE 0 END ))
Ignore xstatus. This is a status mask. Generally, we can use 0 directly.
DECLARE @ ClearPWD varchar (255)
DECLARE @ EncryptedPWD varbinary (255)
SELECT @ ClearPWD = 'test'
SELECT @ EncryptedPWD = CONVERT (varbinary (255), pwdencrypt (@ ClearPWD ))
SELECT pwdcompare (@ ClearPWD, @ EncryptedPWD, 0)
SELECT pwdcompare ('errorpassword', @ EncryptedPWD, 0)
In this way, we can use these two functions to encrypt our passwords.