-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
35 lines (28 loc) · 813 Bytes
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const bcrypt = require('bcrypt');
const emailLookup = function(database, emailAdress) {
let ids = Object.values(database);
for (let user of ids) {
if (user.email === emailAdress) {
return user.id;
}
}
return undefined;
};
const generateRandomString = function(length) {
let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let output = "";
for (let i = 0; i < length; i++) {
output += characters[Math.floor(Math.random() * characters.length)];
}
return output;
};
const generateUsers = function(email, password) {
let id = generateRandomString(9);
let userInfo = {
id: id,
email: email,
password: bcrypt.hashSync(password, 10)
}
return userInfo;
};
module.exports = { emailLookup, generateRandomString, generateUsers };