This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
903aa1e
commit 4bd1c1b
Showing
3 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import knex from "../../../../db/knex"; | ||
import User from "../types/User"; | ||
import bcrypt from "bcrypt"; | ||
|
||
export default async (id: number, oldPassword: string, newPassword: string) => { | ||
const user = await knex<User>("users") | ||
.where({ id }) | ||
.first(); | ||
if (!user) { | ||
return "No user exists"; | ||
} | ||
const passMatches = await bcrypt.compare(oldPassword, user.password); | ||
if (!passMatches) { | ||
return "Password does not match"; | ||
} | ||
const newEncrypted = await bcrypt.hash(newPassword, 12); | ||
await knex<User>("users") | ||
.update({ password: newEncrypted }) | ||
.where({ id }); | ||
}; |
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