summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-20 20:31:18 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-20 20:31:18 +1000
commit428e101a8637e2a854d100fba3151670a8a7a4fd (patch)
treebdc80242b25101406af4d10307ec10644646c061 /util
parentMerge branch 'feat/captchaVerify' into slowcord (diff)
parent2fa (diff)
downloadserver-428e101a8637e2a854d100fba3151670a8a7a4fd.tar.xz
Merge branch '2fa' into slowcord
Diffstat (limited to 'util')
-rw-r--r--util/src/entities/BackupCodes.ts35
-rw-r--r--util/src/entities/User.ts8
-rw-r--r--util/src/entities/index.ts3
3 files changed, 44 insertions, 2 deletions
diff --git a/util/src/entities/BackupCodes.ts b/util/src/entities/BackupCodes.ts
new file mode 100644
index 00000000..d532a39a
--- /dev/null
+++ b/util/src/entities/BackupCodes.ts
@@ -0,0 +1,35 @@
+import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { BaseClass } from "./BaseClass";
+import { User } from "./User";
+import crypto from "crypto";
+
+@Entity("backup_codes")
+export class BackupCode extends BaseClass {
+	@JoinColumn({ name: "user_id" })
+	@ManyToOne(() => User, { onDelete: "CASCADE" })
+	user: User;
+
+	@Column()
+	code: string;
+
+	@Column()
+	consumed: boolean;
+
+	@Column()
+	expired: boolean;
+}
+
+export function generateMfaBackupCodes(user_id: string) {
+	let backup_codes: BackupCode[] = [];
+	for (let i = 0; i < 10; i++) {
+		const code = BackupCode.create({
+			user: { id: user_id },
+			code: crypto.randomBytes(4).toString("hex"),	// 8 characters
+			consumed: false,
+			expired: false,
+		});
+		backup_codes.push(code);
+	}
+
+	return backup_codes;
+}
\ No newline at end of file
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 4035dfe9..954ade5c 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -1,4 +1,4 @@
-import { Column, Entity, FindOneOptions, JoinColumn, ManyToMany, OneToMany, RelationId } from "typeorm";
+import { Column, Entity, FindOneOptions, JoinColumn, OneToMany } from "typeorm";
 import { BaseClass } from "./BaseClass";
 import { BitField } from "../util/BitField";
 import { Relationship } from "./Relationship";
@@ -108,6 +108,12 @@ export class User extends BaseClass {
 	@Column({ select: false })
 	mfa_enabled: boolean; // if multi factor authentication is enabled
 
+	@Column({ select: false, nullable: true })
+	totp_secret?: string;
+
+	@Column({ nullable: true, select: false })
+	totp_last_ticket?: string;
+
 	@Column()
 	created_at: Date; // registration date
 
diff --git a/util/src/entities/index.ts b/util/src/entities/index.ts
index f023d5a6..1b6259ae 100644
--- a/util/src/entities/index.ts
+++ b/util/src/entities/index.ts
@@ -27,4 +27,5 @@ export * from "./Template";
 export * from "./User";
 export * from "./VoiceState";
 export * from "./Webhook";
-export * from "./ClientRelease";
\ No newline at end of file
+export * from "./ClientRelease";
+export * from "./BackupCodes";
\ No newline at end of file