mirror of
https://github.com/logto-io/logto.git
synced 2025-03-17 22:31:28 -05:00
refactor(core): add prefix for password_encryption_method
(#281)
This commit is contained in:
parent
4144051cad
commit
861833c01a
6 changed files with 15 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
import { PasswordEncryptionMethod } from '@logto/schemas';
|
||||
import { UsersPasswordEncryptionMethod } from '@logto/schemas';
|
||||
|
||||
import { hasUserWithId } from '@/queries/user';
|
||||
|
||||
|
@ -56,7 +56,7 @@ describe('encryptUserPassword()', () => {
|
|||
it('generates salt, encrypted and method', () => {
|
||||
const { passwordEncryptionMethod, passwordEncrypted, passwordEncryptionSalt } =
|
||||
encryptUserPassword('user-id', 'password');
|
||||
expect(passwordEncryptionMethod).toEqual(PasswordEncryptionMethod.SaltAndPepper);
|
||||
expect(passwordEncryptionMethod).toEqual(UsersPasswordEncryptionMethod.SaltAndPepper);
|
||||
expect(passwordEncrypted).toHaveLength(64);
|
||||
expect(passwordEncryptionSalt).toHaveLength(21);
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PasswordEncryptionMethod, User } from '@logto/schemas';
|
||||
import { UsersPasswordEncryptionMethod, User } from '@logto/schemas';
|
||||
import { nanoid } from 'nanoid';
|
||||
import pRetry from 'p-retry';
|
||||
|
||||
|
@ -29,10 +29,10 @@ export const encryptUserPassword = (
|
|||
): {
|
||||
passwordEncryptionSalt: string;
|
||||
passwordEncrypted: string;
|
||||
passwordEncryptionMethod: PasswordEncryptionMethod;
|
||||
passwordEncryptionMethod: UsersPasswordEncryptionMethod;
|
||||
} => {
|
||||
const passwordEncryptionSalt = nanoid();
|
||||
const passwordEncryptionMethod = PasswordEncryptionMethod.SaltAndPepper;
|
||||
const passwordEncryptionMethod = UsersPasswordEncryptionMethod.SaltAndPepper;
|
||||
const passwordEncrypted = encryptPassword(
|
||||
userId,
|
||||
password,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createHash } from 'crypto';
|
||||
|
||||
import { PasswordEncryptionMethod } from '@logto/schemas';
|
||||
import { UsersPasswordEncryptionMethod } from '@logto/schemas';
|
||||
import { assertEnv, repeat } from '@silverhand/essentials';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { number, string } from 'zod';
|
||||
|
@ -18,12 +18,12 @@ export const encryptPassword = (
|
|||
id: string,
|
||||
password: string,
|
||||
salt: string,
|
||||
method: PasswordEncryptionMethod
|
||||
method: UsersPasswordEncryptionMethod
|
||||
): string => {
|
||||
assertThat(
|
||||
// FIXME:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
method === PasswordEncryptionMethod.SaltAndPepper,
|
||||
method === UsersPasswordEncryptionMethod.SaltAndPepper,
|
||||
'password.unsupported_encryption_method',
|
||||
{ method }
|
||||
);
|
||||
|
|
|
@ -25,6 +25,6 @@ export enum UserLogResult {
|
|||
Success = 'Success',
|
||||
Failed = 'Failed',
|
||||
}
|
||||
export enum PasswordEncryptionMethod {
|
||||
export enum UsersPasswordEncryptionMethod {
|
||||
SaltAndPepper = 'SaltAndPepper',
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
GeneratedSchema,
|
||||
Guard,
|
||||
} from '../foundations';
|
||||
import { PasswordEncryptionMethod } from './custom-types';
|
||||
import { UsersPasswordEncryptionMethod } from './custom-types';
|
||||
|
||||
export type CreateUser = {
|
||||
id: string;
|
||||
|
@ -20,7 +20,7 @@ export type CreateUser = {
|
|||
primaryEmail?: string | null;
|
||||
primaryPhone?: string | null;
|
||||
passwordEncrypted?: string | null;
|
||||
passwordEncryptionMethod?: PasswordEncryptionMethod | null;
|
||||
passwordEncryptionMethod?: UsersPasswordEncryptionMethod | null;
|
||||
passwordEncryptionSalt?: string | null;
|
||||
name?: string | null;
|
||||
avatar?: string | null;
|
||||
|
@ -35,7 +35,7 @@ export type User = {
|
|||
primaryEmail: string | null;
|
||||
primaryPhone: string | null;
|
||||
passwordEncrypted: string | null;
|
||||
passwordEncryptionMethod: PasswordEncryptionMethod | null;
|
||||
passwordEncryptionMethod: UsersPasswordEncryptionMethod | null;
|
||||
passwordEncryptionSalt: string | null;
|
||||
name: string | null;
|
||||
avatar: string | null;
|
||||
|
@ -50,7 +50,7 @@ const createGuard: Guard<CreateUser> = z.object({
|
|||
primaryEmail: z.string().nullable().optional(),
|
||||
primaryPhone: z.string().nullable().optional(),
|
||||
passwordEncrypted: z.string().nullable().optional(),
|
||||
passwordEncryptionMethod: z.nativeEnum(PasswordEncryptionMethod).nullable().optional(),
|
||||
passwordEncryptionMethod: z.nativeEnum(UsersPasswordEncryptionMethod).nullable().optional(),
|
||||
passwordEncryptionSalt: z.string().nullable().optional(),
|
||||
name: z.string().nullable().optional(),
|
||||
avatar: z.string().nullable().optional(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
create type password_encryption_method as enum ('SaltAndPepper');
|
||||
create type users_password_encryption_method as enum ('SaltAndPepper');
|
||||
|
||||
create table users (
|
||||
id varchar(24) not null,
|
||||
|
@ -6,7 +6,7 @@ create table users (
|
|||
primary_email varchar(128) unique,
|
||||
primary_phone varchar(128) unique,
|
||||
password_encrypted varchar(128),
|
||||
password_encryption_method password_encryption_method,
|
||||
password_encryption_method users_password_encryption_method,
|
||||
password_encryption_salt varchar(128),
|
||||
name varchar(128),
|
||||
avatar varchar(256),
|
||||
|
|
Loading…
Add table
Reference in a new issue