设置密码验证并在react native中确认密码

时间:2019-06-19 06:24:01

标签: javascript validation react-native textinput

我正在尝试匹配密码并确认密码。应用不正确。我有一个注册页面,我在其中注册Firebase身份验证中的电子邮件和密码。我有4个字段用户名,电子邮件,密码和Confirmpassword。

 this.state = {
  password: '',
 confirmPassword: ''
 }

 handleSubmit = () => {
 const { password, confirmPassword } = this.state;
 // perform all neccassary validations
 if (password !== confirmPassword) {
    alert("Passwords don't match");
 } else {
      {this.renderButton()}
 }
 }

但是此代码显示密码不匹配,即使我要输入匹配的密码。

 onButtonPress=()=> {
 this.setState({ error: '', loading: true})
 const { email, password} = this.state;

 firebase.auth()
.createUserWithEmailAndPassword(email,password)
.then ((response) => {
    firebase.auth().currentUser.updateProfile({
        displayName : email,
        displaypassword : password,
    })

    .then(()=>{
      firebase.database().ref('sevenup-a1db1/'+ 
     firebase.auth().currentUser.uid).on('value', function (snapshot) {

          });
     firebase.database().ref('sevenup-a1db1/'+ 
     firebase.auth().currentUser.uid).update({
         email,
         password,

        })
      }).then(this.onLoginSuccess.bind(this))

     . then(()=>{

        this.  props.navigation.navigate('welcome')
    })
    .catch((error) => {
    let errorCode = error.code
    let errorMessage = error.message;
    if (errorCode == 'auth/weak-password') {
    this.onLoginFailure.bind(this)('Weak password!')
    } else {
   this.onLoginFailure.bind(this)(errorMessage)

    }
    });

    console.log(firebase.auth().createUserWithEmailAndPassword.uid);
          });

    }


   onLoginSuccess() {
   this.setState({
   email: '', password: '', error: '', loading: 
   false,confirmpassword:'',username:''

   })
  Alert.alert("success")
  }

  onLoginFailure(errorMessage) {
  this.setState({  error: errorMessage, loading: false })
  Alert.alert("success")

    }

  renderButton() {
  if (this.state.loading) {
  return (
  <View style={styles.spinnerStyle}>
  <ActivityIndicator size={"small"} />

   </View>
  )
  } else {

  return (
  <Button style={styles.loginButton}
  title="Sign in"


  onPress={(this.onButtonPress.bind(this))}

    />
   )
    }
    }

我希望我的密码和确认密码应该相同。

0 个答案:

没有答案