by zx2c4 · 11y ago · 0 comments
https://github.com/hmngwy/weblog.sh/blob/master/lib/ssh/exec...
else if(command[0] === 'password') {
if(args.length===0) {
stream.write('→ You need to specify a password.\n\r');
stream.end();
return;
}
var hash = require('sha256');
var payload = args;
var salt = schemas.randomString(32);
userMeta.user.hash = hash(payload + salt);
userMeta.user.salt = salt;
userMeta.user.token = schemas.randomString(64);
stream.write('… Saving new password'+LB);
userMeta.user.save(function(err, saved){
if(err){
stream.write('→ Password update failed.'+LB);
}
var response = [];
response.push("→ password for "+saved.username+" updated"+LB);
stream.write(response.join(LB));
stream.exit(0);
stream.end();
});
}This is one idea of PHP's that other languages should copy.
When hashing passwords you want a function that is slow and have MANY (but not too many) collisions so that it can not be brute-forced in any direction.
I don't understand this part? Basically if I'm able to find a collision it's like I found the real password, so why is a function with many collisions better for password hashing? Is there a way to differentiate the collisions?
EDIT: typo
What you really want for password hashing is a key derivation function, which will generate a random, unique hash slowly.