r/node • u/mock_coder • Jun 27 '20
Password hashing with NodeJS
https://www.loginradius.com/engineering/blog/password-hashing-with-nodejs/25
u/visicalc_is_best Jun 27 '20
Seriously? Still using “var” in 2020? Smh.
Otherwise good, except for 1000 rounds of pbkdf2. Lop a couple 0s onto the end there, or just use scrypt.
2
u/a-corsican-pimp Jun 27 '20
I might be a tad out of the loop. Is scrypt the next update from bcrypt?
5
4
u/visicalc_is_best Jun 27 '20
Nope, different creators, but generally considered “better” to its memory-hardness (vs CPU), which is harder for ASICs to brute force.
2
u/Triptcip Jun 27 '20
Can't bcrypt scale by increasing the salt rounds though? I assume that's what you mean by memory-hardness...
How is scrypt an improvement?
2
u/spiffytech Jun 27 '20
bcrypt is CPU hard, because it can be tuned to take more CPU than is practical to crack. scrypt is both CPU and memory hard, because it requires a "large" amount of RAM (say, 16MB) to compute the hash. More than you can (or at least, could) put in common ASICs and GPUs, so it's much harder to parallelize.
1
u/frezik Jun 27 '20
You also shouldn't hardcode the tuning parameters, or even the type of password encoding. The system needs to be flexible enough to configure in new parameters on a whim. The fact that people haven't been doing this is why we still have so many sites using unsalted md5 out there (or worse).
On a side point, I hate pbkdf2 just because of how much of an alphabet soup the name is.
-12
u/mobydikc Jun 27 '20
var's been optimized for 25 years.
I don't think the JIT works as well on let yet.
2
u/visicalc_is_best Jun 27 '20
Source?
1
u/mobydikc Jun 28 '20
Looks like these things have been addressed:
https://github.com/petkaantonov/bluebird/wiki/Optimization-killers
1
0
Jun 27 '20
[deleted]
15
u/kisssmysaas Jun 27 '20
You’d be surprised how many people just copy and paste code, without bothering to change them
6
7
u/ChrisAtMakeGoodTech Jun 27 '20
He switched between const and var seemingly at random. He uses let in one place, but could have just used const. It's baffling.
7
u/unknown_char Jun 27 '20
Ignore this blogpost. Rolling your own authentication is a bad idea.
As a minimum, use Passport.js and libraries that follow best practices because it’s very difficult to do it properly. It’ll be easier to use a paid for SaaS like Auth0 and AWS Cognito or free solution like using Oauth providers like Twitter, Facebook or Google.
7
Jun 27 '20
with passportjs you are basically rolling your own authentication system. Passport is just a middleware, you still have to do all the persistence (scary stuff) yourself (at least when working with the local strategy)
it’s not like ruby on rails devise where everything end to end is handled for you.
3
u/Jafit Jun 27 '20
I think any tutorial that teaches people to implement a username and password login system should have a preface of some kind of warning against storing usernames and passwords.
Users are generally terrible at security and will share passwords between applications.
Better to use OAuth and let a big-N company worry about everything, than have your service's database hacked and you be the reason someone's Facebook or online banking password gets compromised.
0
1
0
14
u/chrisjlee84 Jun 27 '20
Why is this upvoted ? Clearly the quality of this post is really low.