in Education by
In my password reset function the user can put in whatever he/she wants. It does not even needs to be a email address. I would like to check for a valid email address, and that the email is registered in Parse Server @IBAction func forgotPasswordButtonTapped(_ sender: Any) { let forgotPasswordAlert = UIAlertController(title: "Forgot password?", message: "Please enter your email address", preferredStyle: .alert) forgotPasswordAlert.view.tintColor = UIColor.red forgotPasswordAlert.addTextField { (textField) in textField.placeholder = "Email address" } forgotPasswordAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) forgotPasswordAlert.addAction(UIAlertAction(title: "Reset password", style: .default, handler: { (action) in let resetEmail = forgotPasswordAlert.textFields?.first?.text PFUser.requestPasswordResetForEmail(inBackground: resetEmail!, block: { (success, error) in if error != nil { let resetFailedAlert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert) resetFailedAlert.view.tintColor = UIColor.red resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(resetFailedAlert, animated: true, completion: nil) } else { let resetEmailSentAlert = UIAlertController(title: "Password reset instructions sendt", message: "Please check your email", preferredStyle: .alert) resetEmailSentAlert.view.tintColor = UIColor.red resetEmailSentAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(resetEmailSentAlert, animated: true, completion: nil) } }) })) //PRESENT ALERT self.present(forgotPasswordAlert, animated: true, completion: nil) } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
In your action you can check for email validity:- forgotPasswordAlert.addAction(UIAlertAction(title: "Reset password", style: .default, handler: { (action) in let resetEmail = forgotPasswordAlert.textFields?.first?.text if self.isValidEmail(testStr: resetEmail) { // Check of email registered on server should be done via this API and API should return error based on that. PFUser.requestPasswordResetForEmail(inBackground: resetEmail!, block: { (success, error) in if error != nil { let resetFailedAlert = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert) resetFailedAlert.view.tintColor = UIColor.red resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(resetFailedAlert, animated: true, completion: nil) } else { let resetEmailSentAlert = UIAlertController(title: "Password reset instructions sendt", message: "Please check your email", preferredStyle: .alert) resetEmailSentAlert.view.tintColor = UIColor.red resetEmailSentAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(resetEmailSentAlert, animated: true, completion: nil) } }) } else { //Show error that email entered is not correct format // present the reset email alertbox again. } })) func isValidEmail(testStr:String) -> Bool { let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) return emailTest.evaluate(with: testStr) }

Related questions

0 votes
    Why does UIImageView remove from Array when I used removeFromSuperview() with Swift? // display UIImageView var ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have a class which has 2 sets of getter & setters. 1 set is the traditional type. These work ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    When you start the application, you should get a line from the Firestore documents and write to an array, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    trying to change method to update the data, because with reloadData have lag let oldIns = insertCounter ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I've searched Apple's documentation, open source projects, and Google, and I cannot seem to find any ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Constraint checking can be disabled in existing _______________ and _____________ constraints so that any data you ... Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    I want to create a request from my application. (iOS and Android - Coded with Xamarin). Explaination: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    How to reset Splunk Admin password?...
asked Oct 31, 2020 in Technology by JackTerrance
0 votes
    I need to be able to change the users' password through a web page (in a controlled environment). ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    Which type of remote URL does not require your user-name and password while for cloning or pushing? A. SSH url B. Https Url...
asked Dec 17, 2022 in Technology by JackTerrance
0 votes
    In _______________ attacks an attacker do not contact with authorizing party for stealing password. (a) passive ... Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
0 votes
    Which of the following attach is not used by LC4 to recover Windows password? (a) Brute-force attack (b) ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
0 votes
    Which of the following is not an example of offline password attack? (a) Dictionary attack (b) Rainbow ... -for-Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
0 votes
    What is ‘git reset’ is used for? What is the default mode of this command?...
asked Nov 4, 2020 in Technology by JackTerrance
...