Skip to content

Instantly share code, notes, and snippets.

@hugoalmeidahh
Created December 16, 2023 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugoalmeidahh/b0cf04a67ba706902b430041563496f8 to your computer and use it in GitHub Desktop.
Save hugoalmeidahh/b0cf04a67ba706902b430041563496f8 to your computer and use it in GitHub Desktop.
bcrypt example
import * as bcrypt from 'bcrypt';
// Gerar um salt
const saltRounds = 10;
const salt = bcrypt.genSaltSync(saltRounds);
// Hash da senha
const password = 'minhaSenha';
const hash = bcrypt.hashSync(password, salt);
// Verificação da senha
const userInputPassword = 'senhaInseridaPeloUsuario';
const isPasswordCorrect = bcrypt.compareSync(userInputPassword, hash);
if (isPasswordCorrect) {
console.log('Senha correta, permitir acesso.');
} else {
console.log('Senha incorreta, negar acesso.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment