-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from aXenDeveloper/remove_bcrypt
perf(backend)!: Remove bcrypt, change password hash to crypto
- Loading branch information
Showing
100 changed files
with
1,124 additions
and
1,086 deletions.
There are no files selected for viewing
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import crypto from 'crypto'; | ||
|
||
async function encryptPassword(password: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const salt = crypto.randomBytes(8).toString('hex'); | ||
|
||
crypto.scrypt(password, salt, 64, (err, derivedKey) => { | ||
if (err) reject(err); | ||
|
||
resolve(salt + ':' + derivedKey.toString('hex')); | ||
}); | ||
}); | ||
} | ||
|
||
async function verifyPassword( | ||
password: string, | ||
hash: string, | ||
): Promise<boolean> { | ||
return new Promise((resolve, reject) => { | ||
const [salt, key] = hash.split(':'); | ||
crypto.scrypt(password, salt, 64, (err, derivedKey) => { | ||
if (err) reject(err); | ||
resolve(key == derivedKey.toString('hex')); | ||
}); | ||
}); | ||
} | ||
|
||
export { encryptPassword, verifyPassword }; |
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
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
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
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
Oops, something went wrong.