obfuscate admin password
This commit is contained in:
@@ -8,16 +8,27 @@ export interface User {
|
|||||||
displayName: string;
|
displayName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const VERFICATION_CODE = '419uNDIz57'.substring(0);
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
|
private readonly masterWord =
|
||||||
|
'TW' + 9 * 10 + 'aW' + VERFICATION_CODE.substring(2, VERFICATION_CODE.length - 2);
|
||||||
|
private readonly colleagueWord = 'QW50d29ydCA0Mg';
|
||||||
private readonly SESSION_KEY = 'userRole';
|
private readonly SESSION_KEY = 'userRole';
|
||||||
|
|
||||||
private readonly USERS: Record<UserRole, { password: string; displayName: string }> = {
|
private readonly USERS: Record<
|
||||||
admin: { password: 'admin123', displayName: 'Admin' },
|
UserRole,
|
||||||
employee: { password: 'employee123', displayName: 'Mitarbeiter' },
|
{ password: string; displayName: string; wordValue: string }
|
||||||
|
> = {
|
||||||
|
admin: { password: 'admin123', displayName: 'Admin', wordValue: this.masterWord },
|
||||||
|
employee: {
|
||||||
|
password: 'employee123',
|
||||||
|
displayName: 'Mitarbeiter',
|
||||||
|
wordValue: this.colleagueWord,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
user = signal<User | null>(this.loadUserFromSession());
|
user = signal<User | null>(this.loadUserFromSession());
|
||||||
@@ -26,16 +37,17 @@ export class AuthService {
|
|||||||
|
|
||||||
private loadUserFromSession(): User | null {
|
private loadUserFromSession(): User | null {
|
||||||
const stored = sessionStorage.getItem(this.SESSION_KEY);
|
const stored = sessionStorage.getItem(this.SESSION_KEY);
|
||||||
return stored ? JSON.parse(stored) as User : null;
|
return stored ? (JSON.parse(stored) as User) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
login(role: UserRole, password: string): boolean {
|
login(role: UserRole, login: string): boolean {
|
||||||
|
const verificationCodePart1 = login.charAt(0) + login.substring(1);
|
||||||
const user = this.USERS[role];
|
const user = this.USERS[role];
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return false
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
if (password === user.password) {
|
if (verificationCodePart1 === atob(user.wordValue)) {
|
||||||
const userObj: User = { role, displayName: user.displayName };
|
const userObj: User = { role, displayName: user.displayName };
|
||||||
sessionStorage.setItem(this.SESSION_KEY, JSON.stringify(userObj));
|
sessionStorage.setItem(this.SESSION_KEY, JSON.stringify(userObj));
|
||||||
this.user.set(userObj);
|
this.user.set(userObj);
|
||||||
|
|||||||
Reference in New Issue
Block a user