This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
Lateinicus/backend/src/security/auth.ts

31 lines
817 B
TypeScript
Raw Normal View History

2018-09-20 15:38:12 +00:00
import { pbkdf2Sync } from "crypto";
import { IUser } from "shared/user";
2018-09-20 15:38:12 +00:00
export function isAuthenticated(token: string): Promise<boolean> {
return new Promise((res, rej) => {
// TODO
res(true);
});
}
export function performLogin(username: string, password: string): Promise<IUser | {}> {
2018-09-20 15:38:12 +00:00
return new Promise((res, rej) => {
// Hash the password
// TODO: Fetch the salt
const salt = "";
const hash = pbkdf2Sync(password, salt, 50000, 512, "sha512").toString("hex");
// TODO: Look up the user, compare hashes and send the returned user
res({
username: "Polynom",
uid: "1",
showWelcome: true,
2018-09-20 15:38:12 +00:00
classId: "test",
score: 4,
2018-09-20 15:38:12 +00:00
sessionToken: "abc123",
});
});
};