Please enable JavaScript.
Coggle requires JavaScript to display documents.
BCRYPT_AUTH, CERR : catch (err) res.sendStatus(500) - Coggle Diagram
BCRYPT_AUTH
SETUP
npm i bcrypt
const bcrypt =
require("bcrypt")
Steps
Create-Salt
Hash-Pass
Using
Salt-n-Pass
Salt
Added-To
Begin-Of
Hashed-Pass
Different-For
All-Pass
Hashes
Different
Same-Pass
Bcrypt
Async-Lib
Router-Func
ShouldBe
Async
LOGIN
app.post(..., asyncFunc)
asyncFunc {..}
const user =
users.find(..)
user => user.name
=== req.body.name
if (user is null)
res.status(400)
.send("No user exists.")
try {..}
if (..)
await bcrypt.compare(..)
res.send("Success")
else
res.send("Invalid credential")
CERR
COMPARING
await bcrypt.compare(..)
password
hashedSavedPass
Returns
Bool
REGISTER
app.post(.., asyncFunc)
asyncFunc {..}
try {..}
const hashedPass =
await bcrypt.hash(..)
req.body.password
salt
const user =
{name: req.body.name,
password: hashedPass}
user.save()
res.sendStatus(201)
CERR
CREATING
Salt
const salt =
await bcrypt.genSalt([rounds])
rounds
10
FewSec
20
FewDays
Hashed-Pass
const hashedPass =
await bcrypt.hash(pass, salt)
DefaultSalt
10
CERR : catch (err) res.sendStatus(500)