I am learning to hash string passwords and store them in an object list.
const bcrypt = require('bcrypt')
var users = []
async function hashPass(pass)
{
try {
const salt = await bcrypt.genSalt(10)
console.log(`Hashing Password: ${pass}`)
const hashedPass = await bcrypt.hash(pass, salt)
console.log(`Hashed Password: ${hashedPass}`)
return hashedPass
} catch (error) {
console.log(error)
}
}
const password = hashPass('pass')
users.push({
'ID': 0,
'Name': 'Ali',
'Email': 'alihaisul.me@gmail.com',
'Password': password
})
console.log(users)
OUTPUT:
[
{
ID: 0,
Name: 'Ali',
Email: 'alihaisul.me@gmail.com',
Password: Promise { <pending> }
}
]
Hashing Password: pass
Hashed Password: $2b$10$r52Lu1K.WxOEcAdyeMBV4eR3EPGRXsgJjktJMXFGY5F7a.Q6yoH1C
I keep getting the "Promise { pending }" in the output. I've researched and tried using async, await, and even the 'then()'. What am I missing here?