Now For Forgot Password VC You Can Use To Reset Password By Getting User Name Or By Getting Email Id Of User… Now Here I It Is The Code For Forgot Password VC.
import UIKit
class forgetpass: UIViewController {
@IBOutlet weak var EmailField: UITextField!
@IBOutlet weak var UserNameField: UITextField!
var db = Database()
var util = Utilities()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func OkAction(_ sender: UIButton) {
if EmailField.text! != ""{
print("email block")
let b = db.selectAll(fromTable: "SELECT password FROM users where email = \"\(EmailField.text!)\"")
if let pass = (b?.firstObject as? NSMutableDictionary)?.value(forKey: "password") as? String{
print(pass)
let alert = util.configPopup(title: "\(EmailField.text!)", message: "password for \(EmailField.text!) is \(pass)")
present(alert, animated: true, completion: nil)
}else{
print("fettching email unsuccessfull")
let alert = util.configPopup(title: "Oops", message: "\(EmailField.text!) \" email not found")
present(alert, animated: true, completion: nil)
}
}else if UserNameField.text! != ""{
print("username block")
let a = db.selectAll(fromTable: "SELECT password FROM users where username = \"\(UserNameField.text!)\"")
if let pass = (a?.firstObject as? NSMutableDictionary)?.value(forKey: "password") as? String{
print(pass)
let alert = util.configPopup(title: "\(UserNameField.text!)", message: "password for \(UserNameField.text!) is \(pass)")
present(alert, animated: true, completion: nil)
}else{
print("fettching password unsuccessfull")
let alert = util.configPopup(title: "Oops", message: "user not found")
present(alert, animated: true, completion: nil)
}
}
else{
if UserNameField.text!.trimmingCharacters(in: .whitespacesAndNewlines) == "" && EmailField.text!.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
let alert = util.configPopup(title: "please", message: "enter something")
present(alert, animated: true, completion: nil)
}
else{
let alert = util.configPopup(title: "Error", message: "Strange Error")
present(alert, animated: true, completion: nil)
}
print("else block")
}
}
@IBAction func GoBacktoLogin(_ sender: Any) {
self.navigationController?.popToRootViewController(animated: true)
}
}