Created
December 16, 2023 01:00
-
-
Save hugoalmeidahh/b0cf04a67ba706902b430041563496f8 to your computer and use it in GitHub Desktop.
bcrypt example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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