-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
206 lines (198 loc) · 6.1 KB
/
App.tsx
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { isValidElement, useEffect, useState } from 'react';
import tw from 'twrnc';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
Button,
Dimensions
} from 'react-native';
import {
responsiveHeight,
responsiveWidth,
responsiveFontSize
} from "react-native-responsive-dimensions";
import { object, string, number} from 'yup';
import { Formik } from 'formik';
import BouncyCheckbox from 'react-native-bouncy-checkbox';
let passwordSchema = object({
length: number().min(4,"Length should be min 4 characters")
.max(16,"Length should be max of 16 characters")
.required("Length is Required"),
});
const App = () =>{
const [password,setPassword] = useState('');
const [ispasswordg,setIspasswordg] = useState<boolean>(false);
const [lower,setLower] = useState<boolean>(true);
const [upper,setUpper] = useState<boolean>(false);
const [numbers,setNumbers] = useState<boolean>(false);
const [symbols,setSymbol] = useState<boolean>(false);
const [Height,setHeight] = useState<number | string>();
const [Width,setWidth] = useState<number| string>();
const generateCharacter = (length:number)=>{
let character:string = "";
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const number = "0123456789";
const symbol = '!@#$%^&*()_+';
if(upper){
character += uppercase ;
}
if(lower){
character += lowercase ;
}
if(numbers){
character += number ;
}
if(symbols){
character += symbol ;
}
const passwordResult = CreatePassword(length,character);
setPassword(passwordResult);
setIspasswordg(true);
}
const CreatePassword = (length:number,character:String)=>{
let result = '';
for(let i=0;i<length;i++){
const characterIndex = Math.round(Math.random() * character.length);
result += character.charAt(characterIndex);
}
return result;
}
const Reset =()=>{
setPassword('');
setLower(true);
setIspasswordg(false);
setUpper(false);
setSymbol(false);
setNumbers(false);
}
useEffect(()=>{
setHeight(Dimensions.get('window').height);
setWidth(Dimensions.get('window').width);
},[]);
console.log(Height);
console.log(Width);
return(
<ScrollView keyboardShouldPersistTaps='handled'>
<SafeAreaView >
<View style={tw`pr-4 pl-4 flex gap-2`}>
<View style={tw`flex items-center`}>
<Text style={tw`text-red-600 text-${responsiveFontSize(.9)} font-bold mt-2 mb-2`}>🔑Password Generator🔑</Text>
</View>
<Formik
initialValues={{length:'' }}
validationSchema={passwordSchema}
onSubmit={values =>{
generateCharacter(+values.length);
}}>
{({
values,
errors,
touched,
isValid,
handleChange,
handleSubmit,
handleReset
}) => (
<>
<View style={tw`flex flex-row items-center justify-between`}>
<Text style={tw`text-xl`}>Password Length</Text>
<TextInput
value={values.length}
keyboardType='numeric'
onChangeText={handleChange('length')} style={tw`border text-xl rounded-md w-20`} placeholder='Ex:10'/>
</View>
<View style={tw`h-5`}>
{touched.length && errors.length && (
<Text style={tw`text-[#e80202]`}>{errors.length}</Text>
)}
</View>
<View style={tw`flex flex-row items-center justify-between`}>
<Text>Include Lowercase</Text>
<BouncyCheckbox
disableBuiltInState
isChecked={lower}
onPress={()=>setLower(!lower)}
fillColor='#238636'
/>
</View>
<View style={tw`flex flex-row items-center justify-between`}>
<Text>Include Uppercase</Text>
<BouncyCheckbox
disableBuiltInState
isChecked={upper}
onPress={()=>setUpper(!upper)}
fillColor='#238636'
/>
</View>
<View style={tw`flex flex-row items-center justify-between`}>
<Text>Include Number</Text>
<BouncyCheckbox
disableBuiltInState
isChecked={numbers}
onPress={()=>setNumbers(!numbers)}
fillColor='#238636'
/>
</View>
<View style={tw`flex flex-row items-center justify-between`}>
<Text>Include Symbol</Text>
<BouncyCheckbox
disableBuiltInState
isChecked={symbols}
onPress={()=>setSymbol(!symbols)}
fillColor='#238636'
/>
</View>
<View style={tw`flex flex-row justify-center mt-4 gap-2`}>
<TouchableOpacity disabled={!isValid} onPress={handleSubmit}>
<View style={tw`bg-[#06c22b] rounded-md p-5`}>
<Text style={tw`text-white font-bold text-xl`}>Generate Password</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={handleReset}>
<View style={tw`bg-[#e80202] rounded-md p-5`}>
<Text style={tw`text-white font-bold text-xl`}>Reset</Text>
</View>
</TouchableOpacity>
</View>
</>
)}
</Formik>
</View>
{ispasswordg?(
<View style={tw`flex items-center mt-10 bg-[#121212] mr-4 ml-4 p-5`}>
<Text style={tw`text-2xl text-white`} selectable>{password}</Text>
</View>
):null}
{ispasswordg?(
<View style={[tw` flex justify-end items-center`,Style.div1]}>
<Text style={tw`text-black text-xl font-bold`}>
Made with ❤️ By Pritam Joardar
</Text>
</View>
):(
<View style={[tw` flex justify-end items-center`,Style.div]}>
<Text style={tw`text-black text-xl font-bold`}>
Made with ❤️ By Pritam Joardar
</Text>
</View>
)}
</SafeAreaView>
</ScrollView>
)
}
const Style = StyleSheet.create({
div:{
height:responsiveHeight(49),
},
div1:{
height:responsiveHeight(35),
}
})
export default App;