Example on how to verify a password from database
See original GitHub issueI’m new to javascript so excuse me if this is trivial, it took me a while to figure it out so i think it should be good to include this in the example to save people some time.
To save the hash to db i need to convert it first to a string. When a user logs in i need to create a new buffer with the saved hash in order to use the verify function.
Using Buffer.from returns the error “Error: hashBuf must be HASH_BYTES (128)” Because the buffer length is 96.
It should be something:
const savedHash = Buffer.alloc(securePassword.HASH_BYTES)
savedHash.write(dbhashedvalue)
Also from what i understand it’s not possible to set the value of securePassword.HASH_BYTES right?
Thank you
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to match username and password in database in SQL
Go on localhost/phpMyAdmin; Create a database with a name check. Now click on SQL and write the query code mentioned below.
Read more >How to check username and password matches the database ...
Just search for the username, and fetch the password. If you search for both, then the search will return zero rows, unless the...
Read more >Salt and Hash a Password in PHP - YouTube
Password Hash and Password Verify - Salt and Hash a Password in PHP ... relatively easily manage password password storage in your database....
Read more >Verifying Password and Confirm password using PHP
php #mysql # database #projectsHey Friends,This is the link for previous part... Complete Sign up and Login system using PHP and ...
Read more >Authenticating a user using PDO and password_verify()
First of all make sure that your passwords are stored in the database using password_hash() function. Assuming we've already got a valid PDO...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@luispadron Specifically with Postgres I would store the hash as
BYTEA
since that allows storing NUL bytes. Have you tried that?Hi folks,
i stumbled into this problem as well yesterday. I use an Express/Node.js/PostgreSQL application and found a rather simple workaround:
The buffer is not converted to a string but to base64 (buffer.toString(‘base64’). The encoding function is provided by the node.js API. This (long) string is then stored in PostgreSQL and later read back and converted back to a buffer by using Buffer.from(‘base64’) from node.js. This way i can store and recover the hash pretty easy!
Encryption
encryptedPassword = pwdSecurity.hashSync(Buffer.from(password)).toString('base64');
Verification
result = pwdSecurity.verifySync(Buffer.from(reqPassword), Buffer.from(dbPassword, 'base64'));
I hope this helps to bridge the time until the announced solution is ready.