Skip to content

Instantly share code, notes, and snippets.

@rts-rob
Created September 11, 2017 06:21
Show Gist options
  • Save rts-rob/a00bc571260b158f55bfd3ded80e0db7 to your computer and use it in GitHub Desktop.
Save rts-rob/a00bc571260b158f55bfd3ded80e0db7 to your computer and use it in GitHub Desktop.
Basic psuedocode example of a signup/login flow with salt and hash
function signup (email, password) {
const salt = uuid();
const hashedPassword = hash(`${salt}${password}`);
// this stores everything in the DB
createUser(email, salt, hashedPassword);
}
function login (request, response) {
// get the salt - SELECT salt FROM users
// WHERE email = ?, [email]
const salt = retrieveSalt(request.email);
const hashedPassword = hash(`${salt}${request.password}`);
// check the database
// SELECT id FROM users
// WHERE email = ? AND hashedPassword = ?,
// [email, password]
response.end(newJWT(tryLogin(email, hashedPassword)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment