Skip to content

Commit

Permalink
style: move function
Browse files Browse the repository at this point in the history
  • Loading branch information
johackim committed Mar 25, 2024
1 parent 679a9be commit 62d7f49
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export const isValidEmail = (email) => new Promise((resolve, reject) => {
});
});

export const generatePassword = (length = 12, wishlist = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@%&*_+') => {
let password;

const isValidPassword = (pwd) => /[A-Z]/.test(pwd) && /[a-z]/.test(pwd) && /[0-9]/.test(pwd) && /[!@%&*_+]/.test(pwd);

do {
password = Array.from(crypto.randomBytes(length)).map((byte) => wishlist[byte % wishlist.length]).join('');
} while (!isValidPassword(password));

return password;
};

export const isValidPassword = (password) => new Promise((resolve, reject) => {
if (password.length < 6) {
reject(new Error('Your password must be at least 6 characters'));
Expand Down Expand Up @@ -104,15 +116,3 @@ export const checkDomain = async (domain) => {

return !regex.test(domain);
};

export const generatePassword = (length = 12, wishlist = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@%&*_+') => {
let password;

const isValidPassword = (pwd) => /[A-Z]/.test(pwd) && /[a-z]/.test(pwd) && /[0-9]/.test(pwd) && /[!@%&*_+]/.test(pwd);

do {
password = Array.from(crypto.randomBytes(length)).map((byte) => wishlist[byte % wishlist.length]).join('');
} while (!isValidPassword(password));

return password;
};

0 comments on commit 62d7f49

Please sign in to comment.