Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- Entity,
- PrimaryGeneratedColumn,
- Column,
- Unique,
- CreateDateColumn,
- UpdateDateColumn
- } from "typeorm";
- import { Length, IsNotEmpty } from "class-validator";
- import * as bcrypt from "bcryptjs";
- @Entity()
- @Unique(["username"])
- export class User {
- @PrimaryGeneratedColumn()
- id: number;
- @Column()
- @Length(4, 20)
- username: string;
- @Column()
- @Length(4, 100)
- password: string;
- @Column()
- @IsNotEmpty()
- role: string;
- @Column()
- @CreateDateColumn()
- createdAt: Date;
- @Column()
- @UpdateDateColumn()
- updatedAt: Date;
- hashPassword() {
- this.password = bcrypt.hashSync(this.password, 8);
- }
- checkIfUnencryptedPasswordIsValid(unencryptedPassword: string) {
- return bcrypt.compareSync(unencryptedPassword, this.password);
- }
- }
Add Comment
Please, Sign In to add comment