swift - Coufused about using UserDefaults to make administrator ID -


i used userdefaults make login screen. question need administrator let apple's examiner can direct sign in app without register again. should next? please me!thanks!

here code:

//this register's code  @iboutlet weak var userregistertextfield: uitextfield!  @iboutlet weak var userregisterpasswordtextfield: uitextfield!  @iboutlet weak var repeatpasswordtextfield: uitextfield!  @ibaction func registerbutton(_ sender: any) {       let userregister = userregistertextfield.text     let userregisterpassword = userregisterpasswordtextfield.text     let userrepeatpassword = repeatpasswordtextfield.text      // save data user register in.     userdefaults.standard.set(userregister, forkey: "userregister")     userdefaults.standard.set(userregisterpassword, forkey: "userregisterpassword")     userdefaults.standard.synchronize()      }     //this login's code. @iboutlet weak var username: uitextfield!  @iboutlet weak var userpassword: uitextfield!  @iboutlet weak var logintext: uilabel!  @iboutlet weak var loginbutton: uibutton!  @ibaction func loginbutton(_ sender: any) {      let userlogin = username.text     let userpasswordtext = userpassword.text     let userpasswordstored = userdefaults.standard.string(forkey: "userregisterpassword")     let userloginstored = userdefaults.standard.string(forkey: "userloginstored")     let vc = self.storyboard?.instantiateviewcontroller(withidentifier: "tabbarcontroller") as! uitabbarcontroller          /*userid , password must same data user registered before*/      if userloginstored == userlogin {     if userpasswordstored == userpasswordtext {              userdefaults.standard.set(true, forkey: "isuserloggedin")             userdefaults.standard.synchronize()             self.present(vc, animated: true, completion: nil)             }      } else {         logintext.text = "your userid or password wrong. please try again"     }  } 

you using 2 different key username. check code below line

in register using key "userregister" store username.

userdefaults.standard.set(userregister, forkey: "userregister") 

where in login using key "userloginstored" retrieve password.

let userloginstored = userdefaults.standard.string(forkey: "userloginstored") 

at both places use same key "userregister" problem resolved.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -