-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.component.ts
52 lines (49 loc) · 1.22 KB
/
app.component.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
password='';
length = 0;
includeLetters= false;
includeNumbers= false;
includeSymbols= false;
onButtonClick(){
const numbers = '0123456789';
const letters = 'abcdefghijklmnopqrstuvwxyz';
const symbols = '!@#$%^&*()';
let validChars = '';
if(this.includeLetters){
validChars += letters;
}
if(this.includeNumbers){
validChars += numbers;
}
if(this.includeSymbols){
validChars += symbols;
}
let generatedPassword ='';
for(let i=0;i<this.length;i++){
const index = Math.floor(Math.random() * validChars.length);
generatedPassword += validChars[index];
}
this.password = generatedPassword;
}
onChangeLength(value : string){
const parsedValue = parseInt(value);
if(!isNaN(parsedValue)){
this.length = parsedValue;
}
}
onChangeUseLetters(){
this.includeLetters = !this.includeLetters;
}
onChangeUseNumbers(){
this.includeNumbers = !this.includeNumbers;
}
onChangeUseSymbols(){
this.includeSymbols = !this.includeSymbols;
}
}