【问题标题】:How to verify Email and password in xcode with firebase如何使用firebase在xcode中验证电子邮件和密码
【发布时间】:2019-10-24 01:32:43
【问题描述】:

我想在 firebase 中使用验证电子邮件验证使用电子邮件和密码登录的用户。

这是我的代码:

@IBAction func Login(_ sender: Any) {
    guard let email = txtUser.text, email != "",
        let password = txtPass.text, password != ""
        else {
            AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all required fields")
            return
        }
    Auth.auth().signIn(withEmail: txtUser.text!, password: txtPass.text!, completion: { (authResult,error) in
        if error != nil{
            AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
        } else if authResult != nil {
            self.performSegue(withIdentifier: "SegueMode", sender: self)
        }
    })
}

【问题讨论】:

  • 你的代码有什么问题?你有什么问题?
  • 在我的代码中,无法使用 firebase 中的验证电子邮件验证用户此登录的电子邮件和密码。@Larme
  • 你能澄清你在问什么吗?听起来好像一旦用户使用电子邮件和密码登录,您就想发送验证电子邮件?如果是这样,则该代码中没有任何内容试图这样做。如果不是,那你在问什么?

标签: ios swift firebase firebase-authentication


【解决方案1】:

你试过了吗

Auth.auth().sendSignInLink(toEmail:email,
                           actionCodeSettings: actionCodeSettings) { error in
  // ...
    if let error = error {
      self.showMessagePrompt(error.localizedDescription)
      return
    }
    // The link was successfully sent. Inform the user.
    // Save the email locally so you don't need to ask the user for it again
    // if they open the link on the same device.
    UserDefaults.standard.set(email, forKey: "Email")
    self.showMessagePrompt("Check your email for link")
    // ...
}

【讨论】:

    【解决方案2】:

    这是我在项目中使用的函数 (注:根据您的要求更改!)

     func loginUser() {
    
        guard let email = txtUserName.text, let password = txtPassword.text else  { return }
    
        Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
            if let error = error {
                print(error.localizedDescription)
                self.lblSuccess.isHidden = false
                self.lblSuccess.textColor = UIColor.red
                self.lblSuccess.text = "Invalid Credential Please Check Your Email and password"
    
            }else if let user = Auth.auth().currentUser {
                let listVC = self.storyboard?.instantiateViewController(withIdentifier: "UserListVC") as! UserListVC
                print(user)
                self.lblSuccess.isHidden = false
                self.lblSuccess.textColor = UIColor.green
                self.lblSuccess.text = "Login SuccessFully!!"
                self.navigationController?.pushViewController(listVC, animated: true)
            }
        })
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-19
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2019-06-11
      相关资源
      最近更新 更多