@accounts/password
Advanced tools
Comparing version 1.0.0-alpha-20231124142337-45cc4d05 to 1.0.0-alpha-20231126181819-d6faf8d5
@@ -81,3 +81,3 @@ import { type User, type TokenRecord, type DatabaseInterface, type AuthenticationService, type ConnectionInformations, type LoginResult, type CreateUserServicePassword, type LoginUserPasswordService, type DatabaseInterfaceSessions, type DatabaseInterfaceUser } from '@accounts/types'; | ||
*/ | ||
validatePassword?: (password?: string) => boolean; | ||
validatePassword?: <T extends User>(password?: string, user?: T) => Promise<boolean>; | ||
/** | ||
@@ -113,3 +113,3 @@ * Function that check if the username is a valid username. | ||
validateEmail(email?: string): boolean; | ||
validatePassword(password?: string): boolean; | ||
validatePassword(password?: string): Promise<boolean>; | ||
validateUsername(username?: string): boolean; | ||
@@ -116,0 +116,0 @@ validateNewUser(user: CreateUserServicePassword): Promise<CreateUserServicePassword> | CreateUserServicePassword; |
@@ -29,3 +29,3 @@ "use strict"; | ||
}, | ||
validatePassword(password) { | ||
async validatePassword(password) { | ||
return (0, validation_1.isString)(password) && password !== ''; | ||
@@ -180,5 +180,2 @@ }, | ||
} | ||
if (!this.options.validatePassword(newPassword)) { | ||
throw new server_1.AccountsJsError(this.options.errors.invalidNewPassword, errors_1.ResetPasswordErrors.InvalidNewPassword); | ||
} | ||
const user = await this.db.findUserByResetPasswordToken(token); | ||
@@ -188,2 +185,5 @@ if (!user) { | ||
} | ||
if (!(await this.options.validatePassword(newPassword, user))) { | ||
throw new server_1.AccountsJsError(this.options.errors.invalidNewPassword, errors_1.ResetPasswordErrors.InvalidNewPassword); | ||
} | ||
const resetTokens = (0, utils_1.getUserResetTokens)(user); | ||
@@ -247,6 +247,6 @@ const resetTokenRecord = resetTokens.find((t) => t.token === token); | ||
async changePassword(userId, oldPassword, newPassword) { | ||
if (!this.options.validatePassword(newPassword)) { | ||
const user = await this.passwordAuthenticator({ id: userId }, oldPassword); | ||
if (!(await this.options.validatePassword(newPassword, user))) { | ||
throw new server_1.AccountsJsError(this.options.errors.invalidPassword, errors_1.ChangePasswordErrors.InvalidPassword); | ||
} | ||
const user = await this.passwordAuthenticator({ id: userId }, oldPassword); | ||
const password = await this.options.hashPassword(newPassword); | ||
@@ -363,3 +363,3 @@ await this.db.setPassword(userId, password); | ||
if (user.password) { | ||
if (!this.options.validatePassword(user.password)) { | ||
if (!(await this.options.validatePassword(user.password))) { | ||
throw new server_1.AccountsJsError(this.options.errors.invalidPassword, errors_1.CreateUserErrors.InvalidPassword); | ||
@@ -366,0 +366,0 @@ } |
{ | ||
"name": "@accounts/password", | ||
"version": "1.0.0-alpha-20231124142337-45cc4d05", | ||
"version": "1.0.0-alpha-20231126181819-d6faf8d5", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"@accounts/server": "1.0.0-alpha-20231124142337-45cc4d05", | ||
"@accounts/server": "^0.33.0", | ||
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0", | ||
@@ -31,3 +31,3 @@ "graphql-modules": "^3.0.0" | ||
"dependencies": { | ||
"@accounts/two-factor": "1.0.0-alpha-20231124142337-45cc4d05", | ||
"@accounts/two-factor": "^0.32.4", | ||
"bcryptjs": "2.4.3", | ||
@@ -38,4 +38,4 @@ "express-validator": "^7.0.1", | ||
"devDependencies": { | ||
"@accounts/server": "1.0.0-alpha-20231124142337-45cc4d05", | ||
"@accounts/types": "1.0.0-alpha-20231124142337-45cc4d05", | ||
"@accounts/server": "^0.33.1", | ||
"@accounts/types": "^0.33.1", | ||
"@types/bcryptjs": "2.4.6", | ||
@@ -42,0 +42,0 @@ "@types/express": "^4.17.21", |
@@ -130,3 +130,3 @@ import { | ||
*/ | ||
validatePassword?: (password?: string) => boolean; | ||
validatePassword?: <T extends User>(password?: string, user?: T) => Promise<boolean>; | ||
/** | ||
@@ -168,3 +168,3 @@ * Function that check if the username is a valid username. | ||
}, | ||
validatePassword(password?: string): boolean { | ||
async validatePassword(password?: string): Promise<boolean> { | ||
return isString(password) && password !== ''; | ||
@@ -370,8 +370,2 @@ }, | ||
} | ||
if (!this.options.validatePassword(newPassword)) { | ||
throw new AccountsJsError( | ||
this.options.errors.invalidNewPassword, | ||
ResetPasswordErrors.InvalidNewPassword | ||
); | ||
} | ||
@@ -386,2 +380,9 @@ const user = await this.db.findUserByResetPasswordToken(token); | ||
if (!(await this.options.validatePassword(newPassword, user))) { | ||
throw new AccountsJsError( | ||
this.options.errors.invalidNewPassword, | ||
ResetPasswordErrors.InvalidNewPassword | ||
); | ||
} | ||
const resetTokens = getUserResetTokens(user); | ||
@@ -478,3 +479,5 @@ const resetTokenRecord = resetTokens.find((t) => t.token === token); | ||
): Promise<void> { | ||
if (!this.options.validatePassword(newPassword)) { | ||
const user = await this.passwordAuthenticator({ id: userId }, oldPassword); | ||
if (!(await this.options.validatePassword(newPassword, user))) { | ||
throw new AccountsJsError( | ||
@@ -486,4 +489,2 @@ this.options.errors.invalidPassword, | ||
const user = await this.passwordAuthenticator({ id: userId }, oldPassword); | ||
const password = await this.options.hashPassword(newPassword); | ||
@@ -685,3 +686,3 @@ await this.db.setPassword(userId, password); | ||
if (user.password) { | ||
if (!this.options.validatePassword(user.password)) { | ||
if (!(await this.options.validatePassword(user.password))) { | ||
throw new AccountsJsError( | ||
@@ -688,0 +689,0 @@ this.options.errors.invalidPassword, |
Sorry, the diff of this file is not supported yet
128642
+ Added@accounts/server@0.33.1(transitive)
+ Added@accounts/two-factor@0.32.4(transitive)
+ Added@accounts/types@0.33.2(transitive)
+ Added@levminer/speakeasy@1.3.3(transitive)
+ Added@types/jsonwebtoken@8.3.9(transitive)
+ Added@types/node@22.13.5(transitive)
+ Addedbase32.js@0.1.0(transitive)
+ Addedemittery@0.8.1(transitive)
+ Addedjsonwebtoken@8.5.1(transitive)
+ Addedjwt-decode@3.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedtslib@2.3.02.3.1(transitive)
+ Addedundici-types@6.20.0(transitive)
- Removed@accounts/server@1.0.0-alpha-20231124142337-45cc4d05(transitive)
- Removed@accounts/two-factor@1.0.0-alpha-20231124142337-45cc4d05(transitive)
- Removed@levminer/speakeasy@1.4.2(transitive)
- Removedemittery@0.13.1(transitive)
- Removedjsonwebtoken@9.0.2(transitive)
- Removedjwt-decode@4.0.0(transitive)
- Removedsemver@7.7.1(transitive)
Updated@accounts/two-factor@^0.32.4