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
24 lines (24 loc) · 1.13 KB
/
Copy pathAuth.ts
File metadata and controls
24 lines (24 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Crypt } from "./Crypt";
import { User } from "@openiap/openflow-api";
import { DBHelper } from "./DBHelper";
import { otel } from "./otel";
import { Span } from "@opentelemetry/api";
export class Auth {
public static async ValidateByPassword(username: string, password: string, parent: Span): Promise<User> {
const span: Span = 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 DBHelper.FindByUsername(username, null, span);
if (user === null || user === undefined) { return null; }
if ((await Crypt.compare(password, user.passwordhash)) !== true) { return null; }
return user;
} catch (error) {
span.recordException(error);
throw error;
} finally {
otel.endSpan(span);
}
}
}