mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-10-28 03:25:55 +08:00
Reflecion of #589
This commit is contained in:
@ -9,19 +9,21 @@
|
|||||||
### Пример кода
|
### Пример кода
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
try {
|
||||||
// asynchronously generate a secure password using 10 hashing rounds
|
// asynchronously generate a secure password using 10 hashing rounds
|
||||||
bcrypt.hash('myPassword', 10, function(err, hash) {
|
const hash = await bcrypt.hash('myPassword', 10);
|
||||||
// Store secure hash in user record
|
// Store secure hash in user record
|
||||||
});
|
|
||||||
|
|
||||||
// compare a provided password input with saved hash
|
// compare a provided password input with saved hash
|
||||||
bcrypt.compare('somePassword', hash, function(err, match) {
|
const match = await bcrypt.compare('somePassword', hash);
|
||||||
if(match) {
|
if (match) {
|
||||||
// Passwords match
|
// Passwords match
|
||||||
} else {
|
} else {
|
||||||
// Passwords don't match
|
// Passwords don't match
|
||||||
}
|
}
|
||||||
});
|
} catch {
|
||||||
|
logger.error('could not hash password.')
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Что говорят другие блогеры
|
### Что говорят другие блогеры
|
||||||
|
|||||||
Reference in New Issue
Block a user