All checks were successful
Test CI / build (push) Successful in 1m21s
- 비밀번호 초기화 로직 1차 구현(테스트 필요)
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
export class Generator {
|
|
static getVerificationCode() {
|
|
return Math.random().toString().slice(2, 8);
|
|
}
|
|
|
|
private static getRandomCharacter(string: string) {
|
|
return string[Math.floor(Math.random() * string.length)];
|
|
}
|
|
|
|
private static getShuffledString(string: string) {
|
|
let arr = string.split('');
|
|
|
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
}
|
|
|
|
return arr.join('');
|
|
}
|
|
|
|
static getResetPasswordCode() {
|
|
const alphabets = 'abcdefghijklmnopqrstuvwxyz';
|
|
const numbers = '0123456789';
|
|
const specials = '!@#$%^';
|
|
const all = alphabets + numbers + specials;
|
|
|
|
let resetPasswordCode = Generator.getRandomCharacter(alphabets);
|
|
let requiredNumber = Generator.getRandomCharacter(numbers);
|
|
let requiredSpecial = Generator.getRandomCharacter(specials);
|
|
|
|
let shuffledRestPart = Generator.getShuffledString(all).slice(0, 5);
|
|
|
|
let shuffledRestCode = Generator.getShuffledString(requiredNumber + requiredSpecial + shuffledRestPart);
|
|
|
|
return resetPasswordCode + shuffledRestCode;
|
|
}
|
|
} |