xcode 如何添加和检查确认密码以通过 Parse 注册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27210087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add and check for a confirm password to Sign Up via Parse
提问by kareem
On my sign up page I want users to confirm the password they chose using a confirm password textfield. I am using Swift.
在我的注册页面上,我希望用户使用确认密码文本字段来确认他们选择的密码。我正在使用 Swift。
Here is my code for my Sign Up
这是我的注册代码
if(newUser.password != self.confirmPassword.text){
let alertController = UIAlertController(title: "Sign Up Failed", message: "Sorry, your Passwords were not matching.", preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
// ...
}
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true) {
// ...
}
}
This is in my @IBAction func confirmButton(sender: AnyObject)
这是在我的 @IBAction func confirmButton(sender: AnyObject)
Edit:
编辑:
I am not getting an error, Parse still sign ups users if I just fill out a two different passwords or no password at all.
我没有收到错误消息,如果我只填写两个不同的密码或根本没有密码,Parse 仍然会注册用户。
Thanks.
谢谢。
回答by Jacob
Here is how I normally do it:
这是我通常的做法:
func registerButtonTapped() {
var a = false
var b = false
if passwordField.text == confirmField.text {
a = true
} else {
//Passwords dont match
}
if(passwordField.text == "" || confirmField.text == "") {
//alert saying there are empty fields
} else {
b = true
}
if a == true && b == true {
//Signup code
}
}
回答by Darshan SK
The previous answer is correct but I prefer to do the same with two if statements, the first if statement checks if all the textfields have text in case some textfields are missing we have an alert for the user("Please Enter All text Fields"). The second if statement checks if the passwords are equal and provides another alert("Passwords don't Match"). If all the requirements are meet the function returns true.
上一个答案是正确的,但我更喜欢对两个 if 语句做同样的事情,第一个 if 语句检查所有文本字段是否都有文本,以防某些文本字段丢失我们为用户发出警报(“请输入所有文本字段”) . 第二个 if 语句检查密码是否相等并提供另一个警报(“密码不匹配”)。如果所有要求都满足,函数返回真。
func validationOfTextFields() -> Bool{
var a = false
if(signUpPassword.text == "" || signUpConfirmPassword.text == "" || signUpName.text == "" || signUpEmail.text == "" || signUpStudentMatrix.text == "")
{
let alertController = UIAlertController(title: "Error", message: "Please Enter All text Fields", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
if signUpPassword.text != signUpConfirmPassword.text {
let alertController = UIAlertController(title: "Error", message: "Passwords don't Match", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
else{
a = true
}
}
return a
}