question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example on how to verify a password from database

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
emilbayescommented, Apr 25, 2018

@luispadron Specifically with Postgres I would store the hash as BYTEA since that allows storing NUL bytes. Have you tried that?

1reaction
mseefeldtcommented, Oct 3, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found