ios - 如何使用firebase在xcode中验证电子邮件和密码
问题描述
我想使用 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)
}
})
}
解决方案
这是我在项目中使用的功能(注意:根据您的要求更改!)
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)
}
})
}
推荐阅读
- reactjs - React npm run build 主页不起作用
- python - Python3:转换为字典时如何处理包含二进制字符串的xml
- flask - Flask-MQTT 未连接到代理
- python - 为什么这个参数在这个 super().__init__() 方法中出现了两次?
- sql - 如何将 Store_ID 的所有值拉入我的雪花查询?
- wordpress - WordPress 中的树枝/木材无法正确显示价格
- c# - xamarin 形式的 sqlite-net 和 Async 方法
- emacs - Emacs 完成点问题
- scala - 如何在scala 3宏中匹配函数Expr
- c++ - 不同版本的g++重载解析结果不一致