forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.ts
More file actions
23 lines (23 loc) · 1.12 KB
/
Copy pathAuth.ts
File metadata and controls
23 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Crypt } from "./Crypt";
import { User } from "@openiap/openflow-api";
import { Span } from "@opentelemetry/api";
import { Logger } from "./Logger";
export class Auth {
public static async ValidateByPassword(username: string, password: string, parent: Span): Promise<User> {
const span: Span = Logger.otel.startSubSpan("Auth.ValidateByPassword", parent);
try {
if (username === null || username === undefined || username === "") { throw Error("Username cannot be null"); }
span?.setAttribute("username", username);
if (password === null || password === undefined || password === "") { throw Error("Password cannot be null"); }
const user: User = await Logger.DBHelper.FindByUsername(username, null, span);
if (user === null || user === undefined) { return null; }
if ((await Crypt.compare(password, user.passwordhash, span)) !== true) { return null; }
return user;
} catch (error) {
span?.recordException(error);
throw error;
} finally {
Logger.otel.endSpan(span);
}
}
}