mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Support HashedPassword workflow for logins (#4469)
* Support HashedPassword workflow for logins * Address comments in PR
This commit is contained in:
parent
45d86e7ab7
commit
43eee6b32e
8 changed files with 93 additions and 7 deletions
|
|
@ -1,2 +1,3 @@
|
|||
export * from "./guid.util";
|
||||
export * from "./sanitizeHtml.util";
|
||||
export * from "./sanitizeHtml.util";
|
||||
export * from "./passwordHasher";
|
||||
26
webclient/src/websocket/utils/passwordHasher.ts
Normal file
26
webclient/src/websocket/utils/passwordHasher.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import sha512 from 'crypto-js/sha512';
|
||||
import Base64 from 'crypto-js/enc-base64';
|
||||
|
||||
const HASH_ROUNDS = 1_000;
|
||||
const SALT_LENGTH = 16;
|
||||
|
||||
export const hashPassword = (salt: string, password: string): string => {
|
||||
let hashedPassword = salt + password;
|
||||
for (let i = 0; i < HASH_ROUNDS; i++) {
|
||||
// WHY DO WE DO IT THIS WAY?
|
||||
hashedPassword = sha512(hashedPassword);
|
||||
}
|
||||
|
||||
return salt + Base64.stringify(hashedPassword);
|
||||
};
|
||||
|
||||
export const generateSalt = (): string => {
|
||||
const characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
let salt = "";
|
||||
for (let i = 0; i < SALT_LENGTH; i++) {
|
||||
salt += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
|
||||
return salt;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue