mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
Hello airbnb
This commit is contained in:
1 parent
f9468536de
commit
8c195661d7
78 files changed
+2032
-1471
No files matched your search
+9
-8
@@ -1,26 +1,27 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
module.exports = {
|
||||
_b64encode: str => new Buffer(str).toString('base64'),
|
||||
_b64decode: str => new Buffer(str, 'base64').toString(),
|
||||
_md5: str => crypto.createHash('md5').update(str).digest('hex'),
|
||||
_sha1: str => crypto.createHash('sha1').update(str).digest('hex'),
|
||||
_b64encode: (str) => Buffer.from(str).toString('base64'),
|
||||
_b64decode: (str) => Buffer.from(str, 'base64').toString(),
|
||||
_md5: (str) => crypto.createHash('md5').update(str).digest('hex'),
|
||||
_sha1: (str) => crypto.createHash('sha1').update(str).digest('hex'),
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt
|
||||
* @param {string} hash
|
||||
*/
|
||||
check(password, salt, hash) {
|
||||
return hash == this.hash(password, salt);
|
||||
return hash === this.hash(password, salt);
|
||||
},
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt
|
||||
*/
|
||||
hash(password, salt) {
|
||||
let res = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256');
|
||||
const res = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256');
|
||||
return res.toString('Hex');
|
||||
},
|
||||
salt() {
|
||||
return String.random();
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user