Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top