문제

Data table: people_t

Columns:

Username - nvarchar(200)
PasswordHash - nvarchar(1000)

Query:

I want to change multiple passwords of type hash to be the usernames. After the command, the passwords should still be hashed but the actual password will be the user's username. E.g.

  • Username: johndoe
  • PasswordHash: iamjohn

Will become:

  • Username: johndoe
  • PasswordHash: johndoe

I am trying the following:

DECLARE @UserPass SHA1 --Var for storage of username
SET @UserPass=UserName --Add current Username's to UserPass var

UPDATE people_t --Update the people_t
SET PasswordHash=@UserPass --Do the job

Do I even need a WHERE clause or what am I doing wrong here?

Thanks in advance folks.

도움이 되었습니까?

해결책

I think what you might want (for sql server) is this:

update people_t set passwordhash =  HASHBYTES('SHA1', username)

Your pseudo code seems to set a single hash (which would be based on one username) and then is updating all people with that single username.


Not sure what the SHA1 type is in your code above - don't recognize that.

다른 팁

You could use any algorithm : MD2 , MD4 , MD5 , SHA , SHA1 , SHA2_256 , SHA2_512

Your Query :

UPDATE people_t set PasswordHash =  HASHBYTES('ALGORITHM', UserName)

Replace ALGORITHM with any one mentioned above.

Documentation
How to choose an encryption algorithm

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top