/
main.dart
174 lines (166 loc) · 5.45 KB
/
main.dart
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import 'package:flutter/material.dart';
import 'package:random_password_generator/random_password_generator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isWithLetters = true;
bool _isWithUppercase = false;
bool _isWithNumbers = false;
bool _isWithSpecial = false;
double _numberCharPassword = 8;
String newPassword = '';
Color _color = Colors.blue;
String isOk = '';
TextEditingController _passwordLength = TextEditingController();
final password = RandomPasswordGenerator();
@override
void initState() {
super.initState();
}
checkBox(String name, Function onTap, bool value) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(name),
Checkbox(value: value, onChanged: onTap),
],
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Random Password Generator'),
),
body: Center(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
checkBox('Upper Case', (bool value) {
_isWithUppercase = value;
setState(() {});
}, _isWithUppercase),
checkBox('Lower Case', (bool value) {
_isWithLetters = value;
setState(() {});
}, _isWithLetters)
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
checkBox('Symbols', (bool value) {
_isWithSpecial = value;
setState(() {});
}, _isWithSpecial),
checkBox('Numbers', (bool value) {
_isWithNumbers = value;
setState(() {});
}, _isWithNumbers)
],
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.all(15.0),
child: TextField(
controller: _passwordLength,
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
filled: true,
fillColor: Colors.grey[300],
labelText: 'Enter Length',
labelStyle: TextStyle(color: Colors.blue),
),
keyboardType: TextInputType.number,
),
),
SizedBox(
height: 20,
),
FlatButton(
onPressed: () {
if (_passwordLength.text.trim().isNotEmpty)
_numberCharPassword =
double.parse(_passwordLength.text.trim());
newPassword = password.randomPassword(
letters: _isWithLetters,
numbers: _isWithNumbers,
passwordLength: _numberCharPassword,
specialChar: _isWithSpecial,
uppercase: _isWithUppercase);
print(newPassword);
double passwordstrength =
password.checkPassword(password: newPassword);
if (passwordstrength < 0.3) {
_color = Colors.red;
isOk = 'This password is weak!';
} else if (passwordstrength < 0.7) {
_color = Colors.blue;
isOk = 'This password is Good';
} else {
_color = Colors.green;
isOk = 'This passsword is Strong';
}
setState(() {});
},
child: Container(
color: Colors.red,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Generator Password',
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
)),
SizedBox(
height: 10,
),
if (newPassword.isNotEmpty && newPassword != null)
Center(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
isOk,
style: TextStyle(color: _color, fontSize: 25),
),
),
)),
if (newPassword.isNotEmpty && newPassword != null)
Center(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
newPassword,
style: TextStyle(color: _color, fontSize: 25),
),
),
))
],
)),
),
);
}
}