import { Column } from 'typeorm'; export abstract class VersionablePersistedPassword { /** * Used to designate persisted passwords that were hashed with different * values than the one that is currently running. Useful in case there is a * need to change the algorithm that is running in the future. In which * case, future passwords can be encoded using a different algorith but it * will still be easy to verify passwords encoded with a prior methodology * (and re-encode them using new methodology). */ @Column({ type: 'int', nullable: false, }) algorithmVersion!: number; } /** * The information about the password that is stored in the database */ export class PersistedPasswordV1 implements VersionablePersistedPassword { @Column({ type: 'int', nullable: false, }) algorithmVersion = 1; /** * Salt value for this specific password. Should be different for each * user/password. */ @Column({ type: 'varchar', nullable: false, }) salt!: string; /** * The encoding used to convert the salt from bytes to a string. */ @Column({ type: 'varchar', nullable: false, }) saltEncoding!: BufferEncoding; /** * The hash and salted password created via the user provided password. */ @Column({ type: 'varchar', nullable: false, }) hash!: string; /** * The number of iterations on the algorithm performed to create the hashed * and salted password. */ @Column({ type: 'int', nullable: false, }) iterations!: number; /** * Requested length of the final hashed and salted password. */ @Column({ type: 'int', nullable: false, }) length!: number; /** * The hash function used */ @Column({ type: 'varchar', nullable: false, }) hashFunction!: string; } /** * Data representing what should be persisted for a password */ export class PersistedPassword extends PersistedPasswordV1 {}