-
Notifications
You must be signed in to change notification settings - Fork 11
Password verification done #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ksanc159@fiu.edu |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,33 @@ | ||
| import React, {useEffect, useState} from 'react'; | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { | ||
| Keyboard, | ||
| Text, | ||
| TextInput as TextBox, | ||
| TouchableOpacity, | ||
| View, | ||
| TouchableHighlight, | ||
| Platform, | ||
| KeyboardAvoidingView, | ||
| StyleSheet, | ||
| Alert, | ||
| Platform, | ||
| } from 'react-native'; | ||
| import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
| import {MaterialCommunityIcons as Icon} from '@expo/vector-icons'; | ||
| import { MaterialCommunityIcons as Icon } from '@expo/vector-icons'; | ||
| import appStyles from './AppStyles'; | ||
| import Button from './Button'; | ||
| import translate from './getLocalizedText'; | ||
| import poorPasswords from './poorPasswords'; | ||
|
|
||
| export default SignUpPassword = (props) => { | ||
| const [password, setPassword] = useState(''); | ||
| const [repeat, setRepeat] = useState(''); | ||
| const {liveMiami} = props.route.params; | ||
| const {name} = props.route.params; | ||
| const {dob} = props.route.params; | ||
| const {email} = props.route.params; | ||
| const {phone} = props.route.params; | ||
| const { liveMiami, name, dob, email, phone } = props.route.params; | ||
| const [isSecureEntry, setIsSecureEntry] = useState(true); | ||
| const [show, setShow] = React.useState(false); | ||
| const [showRepeat, setShowRepeat] = React.useState(false); | ||
| const [visible, setVisible] = React.useState(true); | ||
| const [visibleRepeat, setVisibleRepeat] = React.useState(true); | ||
| const [passwordStrength, setPasswordStrength] = useState(0); | ||
| const special_chars = ['!', '#', '$', '*', '%']; | ||
| let containsSpecialChar = false; | ||
|
|
||
|
|
@@ -41,13 +40,35 @@ export default SignUpPassword = (props) => { | |
| }); | ||
| }, []); | ||
|
|
||
| const checkPasswordStrength = (password) => { | ||
| const lowerCase = /[a-z]/.test(password); | ||
| const upperCase = /[A-Z]/.test(password); | ||
| const number = /[0-9]/.test(password); | ||
| const symbol = /[!@#$%^&*(),.?":{}|<>]/.test(password); | ||
|
|
||
| const isPoor = password.length <= 4 || poorPasswords.includes(password); | ||
| const isMedium = password.length >= 5 && [lowerCase, upperCase, number, symbol].filter(Boolean).length === 3 && !poorPasswords.includes(password); | ||
| const isHigh = password.length >= 5 && [lowerCase, upperCase, number, symbol].filter(Boolean).length === 4 && !poorPasswords.includes(password); | ||
|
|
||
| if (isPoor) return 0; | ||
| if (isMedium) return 1; | ||
| if (isHigh) return 2; | ||
| return 0; | ||
| }; | ||
|
|
||
| let onPress = () => { | ||
| if (passwordStrength === 0) { | ||
| alert(translate('passwordTooWeak')); | ||
| return; | ||
| } | ||
|
|
||
| for (let i = 0; i < password.length; i++) { | ||
| if (special_chars.includes(password[i])) { | ||
| containsSpecialChar = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (password !== repeat) { | ||
| alert(translate('passwordMismatch')); | ||
| } else if (!password || !repeat) { | ||
|
|
@@ -56,10 +77,34 @@ export default SignUpPassword = (props) => { | |
| alert(translate('passwordTooShort')); | ||
| } else if (!containsSpecialChar) { | ||
| alert(translate('passwordWeak')); | ||
| } else if (passwordStrength === 1) { | ||
| Alert.alert( | ||
| "Warning", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest you use |
||
| "The password entered has a medium level of strength we suggest that a good password must have at least 6 characters, a lowercase, an uppercase, a number, and a symbol. Do you want to improve it or continue with the one that you have?", | ||
| [ | ||
| { | ||
| text: 'Edit', | ||
| onPress: () => { }, | ||
| style: 'cancel' | ||
| }, | ||
| { | ||
| text: 'Continure', | ||
| onPress: () => { | ||
| props.navigation.navigate('SignUpYesorNoPregnant', { | ||
| liveMiami, | ||
| name, | ||
| dob, | ||
| email, | ||
| phone, | ||
| password, | ||
| question: translate('areYouPregnant'), | ||
| value: 'pregnant', | ||
| }); | ||
| } | ||
| } | ||
| ] | ||
| ); | ||
| } else { | ||
| // props.setUserInfo({password}); | ||
| // AsyncStorage.setItem('pass', password); | ||
| // AsyncStorage.setItem('repeat', repeat); | ||
| props.navigation.navigate('SignUpYesorNoPregnant', { | ||
| liveMiami, | ||
| name, | ||
|
|
@@ -72,6 +117,19 @@ export default SignUpPassword = (props) => { | |
| }); | ||
| } | ||
| }; | ||
|
|
||
| const getPasswordStrengthColor = () => { | ||
| if (passwordStrength === 0) return 'pink'; | ||
| if (passwordStrength === 1) return 'blue'; | ||
| if (passwordStrength === 2) return '#298000'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to not hardcode colors. |
||
| }; | ||
|
|
||
| const getPasswordStrengthText = () => { | ||
| if (passwordStrength === 0) return 'Poor'; | ||
| if (passwordStrength === 1) return 'Medium'; | ||
| if (passwordStrength === 2) return 'High'; | ||
| }; | ||
|
|
||
| return ( | ||
| <KeyboardAvoidingView | ||
| behavior={Platform.OS === 'ios' ? 'padding' : 'height'} | ||
|
|
@@ -96,14 +154,17 @@ export default SignUpPassword = (props) => { | |
| <Text style={appStyles.titleBlue}> | ||
| {translate('createPassword')} | ||
| </Text> | ||
| <View style={{paddingTop: appStyles.win.height * 0.05}}> | ||
| <View style={{ paddingTop: appStyles.win.height * 0.05 }}> | ||
| <View> | ||
| <TextBox | ||
| placeholderTextColor={appStyles.DefaultPlaceholderTextColor} | ||
| style={appStyles.TextInputMask} | ||
| secureTextEntry={visible} | ||
| placeholder={translate('passwordInput')} | ||
| onChangeText={setPassword} | ||
| onChangeText={(text) => { | ||
| setPassword(text); | ||
| setPasswordStrength(checkPasswordStrength(text)); | ||
| }} | ||
| /> | ||
| <TouchableOpacity | ||
| style={styles.eyeShowPassword} | ||
|
|
@@ -137,14 +198,19 @@ export default SignUpPassword = (props) => { | |
| }} | ||
| > | ||
| <Icon | ||
| name={ | ||
| showRepeat === false ? 'eye-outline' : 'eye-off-outline' | ||
| } | ||
| name={showRepeat === false ? 'eye-outline' : 'eye-off-outline'} | ||
| size={26} | ||
| color={appStyles.pinkColor} | ||
| /> | ||
| </TouchableOpacity> | ||
| </View> | ||
|
|
||
| <View style={{ paddingTop: 20, paddingLeft: 15 }}> | ||
| <Text style={{ color: getPasswordStrengthColor(), fontSize: 20 }}> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, you dynamically change the values. |
||
| {getPasswordStrengthText()} | ||
| </Text> | ||
| </View> | ||
|
|
||
| </View> | ||
| </View> | ||
| </View> | ||
|
|
@@ -173,4 +239,4 @@ const styles = StyleSheet.create({ | |
| right: 30, | ||
| top: 25, | ||
| }, | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need the ispoor check as you already have a default return 0.