Skip to content

Commit

Permalink
Fix an issue with lost password on MariaDB (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
evert authored Feb 11, 2025
1 parent c58de2b commit 1ac1563
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Changelog
* This small refactoring allows us to emit `too_many_failed_login_attempts`
from the `authorization_challenge` system. Before, it emitted
`invalid_username_or_password` which is confusing.
* Limit passwords to 72 characters to avoid issues with bcrypt trunctating the
input.
* Fix an issue with lost password not working on MariaDB.


0.29.0 (2025-02-07)
Expand Down
12 changes: 9 additions & 3 deletions src/user/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ export async function createPassword(user: User, password: string): Promise<void
export async function updatePassword(user: User, password: string): Promise<void> {

assertValidPassword(password);
const passwordHash = await bcrypt.hash(password, 12);
await db('user_passwords').insert({
user_id: user.id,
password: await bcrypt.hash(password, 12)
password: passwordHash,
})
.onConflict('user_id')
.merge();
.onConflict('user_id')

Check failure on line 28 in src/user/service.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
.merge({

Check failure on line 29 in src/user/service.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
password: passwordHash,

Check failure on line 30 in src/user/service.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 4
});

Check failure on line 31 in src/user/service.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2

}

Expand Down Expand Up @@ -69,6 +72,9 @@ function assertValidPassword(password: string) {
if (password.length < 8) {
throw new UnprocessableContent('Passwords must be at least 8 characters');
}
if (password.length > 72) {
throw new UnprocessableContent('Passwords must be at most 72 characters');
}

}

Expand Down

0 comments on commit 1ac1563

Please sign in to comment.