Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I hash a string with Node.js #31

Closed
janbaer opened this issue Aug 29, 2016 · 0 comments
Closed

How can I hash a string with Node.js #31

janbaer opened this issue Aug 29, 2016 · 0 comments
Labels

Comments

@janbaer
Copy link
Owner

janbaer commented Aug 29, 2016

You can use the builtin crypto module for that.

const crypto = require('crypto');

function hashPassword(password, salt, algorithm='sha256'){
    let hash = crypto.createHmac(algorithm, salt); 
    hash.update(password);
    let value = hash.digest('hex');

    return {
        salt: salt,
        passwordHash: value
    };
}

See also this article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant