feat: added export for setting passwords

pull/177/head
tycrek 2 years ago
parent 6be768d655
commit 6cfd353a54
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -92,6 +92,22 @@ export const createNewUser = (username: string, passhash: string, admin: boolean
fs.writeJson(authPath, authData, { spaces: '\t' });
});
export const setUserPassword = (unid: string, password: string): Promise<User> => new Promise(async (resolve, reject) => {
// Find the user
const user = users.find((user) => user.unid === unid);
if (!user) return reject(new Error('User not found'));
// Set the password
user.passhash = await bcrypt.hash(password, 10);
// Save the new user to auth.json
const authPath = path('auth.json');
const authData = fs.readJsonSync(authPath) as Users;
const userIndex = authData.users.findIndex((user) => user.unid === unid);
authData.users[userIndex] = user;
fs.writeJson(authPath, authData, { spaces: '\t' });
});
/**
* Called by ass.ts on startup

Loading…
Cancel
Save