diff options
author | MCMXC <16797721+mcmxcdev@users.noreply.github.com> | 2024-02-10 18:37:40 -0700 |
---|---|---|
committer | Vijay A <vraravam@users.noreply.github.com> | 2024-02-13 06:59:44 +0530 |
commit | e1c47572a6235fd8fd20af888ac3a11c7ae1369d (patch) | |
tree | 2dccff36a441916d7014037cef3f7ce84a790cad /helpers/PasswordHash.ts | |
parent | refactor: project maintenance (diff) | |
download | ferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.tar.gz ferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.tar.zst ferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.zip |
updates
Diffstat (limited to 'helpers/PasswordHash.ts')
-rw-r--r-- | helpers/PasswordHash.ts | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/helpers/PasswordHash.ts b/helpers/PasswordHash.ts index 5c73195..300186d 100644 --- a/helpers/PasswordHash.ts +++ b/helpers/PasswordHash.ts | |||
@@ -1,14 +1,17 @@ | |||
1 | import User from '#app/Models/User' | 1 | import User from '#app/Models/User'; |
2 | import hash from '@adonisjs/core/services/hash' | 2 | import hash from '@adonisjs/core/services/hash'; |
3 | 3 | ||
4 | export async function handleVerifyAndReHash(user: User, passwordToTest: string): Promise<boolean> { | 4 | export async function handleVerifyAndReHash( |
5 | user: User, | ||
6 | passwordToTest: string, | ||
7 | ): Promise<boolean> { | ||
5 | // Verify password | 8 | // Verify password |
6 | const usesLegacyHasher = /^\$2[aby]/.test(user.password) | 9 | const usesLegacyHasher = /^\$2[aby]/.test(user.password); |
7 | let isMatchedPassword = false | 10 | let isMatchedPassword = false; |
8 | 11 | ||
9 | isMatchedPassword = await (usesLegacyHasher | 12 | isMatchedPassword = await (usesLegacyHasher |
10 | ? hash.use('legacy').verify(user.password, passwordToTest) | 13 | ? hash.use('legacy').verify(user.password, passwordToTest) |
11 | : hash.verify(user.password, passwordToTest)) | 14 | : hash.verify(user.password, passwordToTest)); |
12 | 15 | ||
13 | // TODO: For some reason this is not working (user can't login after re-hashing) | 16 | // TODO: For some reason this is not working (user can't login after re-hashing) |
14 | // rehash user password | 17 | // rehash user password |
@@ -17,5 +20,5 @@ export async function handleVerifyAndReHash(user: User, passwordToTest: string): | |||
17 | // await user.save(); | 20 | // await user.save(); |
18 | // } | 21 | // } |
19 | 22 | ||
20 | return isMatchedPassword | 23 | return isMatchedPassword; |
21 | } | 24 | } |