Idea: The front desk input account password, backstage custom a function checknamepwd () to verify the account password is correct or not, in the controller call, wherein, CHECKNAMEPWD () method verifies the account password correctness is first through the account to find the password, Then the search out the password and user input password comparison, the same login success, otherwise login failed!
First, define a function checknamepwd () in the model class.
Public functionChecknamepwd ($name,$pwd) { //① based on $name query whether there is a record of the specified name//find the entire record by $name $res=$this->where ("Mg_name="$name' ")find (); if($res) { //② Compare the password of the queried record with the password entered by the user if($res[' Mg_pwd ']===$pwd) { return $res; } }Else{ return NULL; } }
The controller receives information entered by the user and calls the Checknamepwd () method
$manager=New\model\managermodel ();$name=$_post[' Admin_user '];$pwd=$_post[' ADMIN_PSD '];//Verify that the entire record is returned successfully, otherwise null is returned$info=$manager->checknamepwd ($name,$pwd); if($info) { //verify success, give user information session persistence operation (NAME,ID)Session (' admin_id ',$info[' mg_id ']); session (' Admin_name ',$info[' Mg_name ']); //Jump back Home $this->redirect (' Index/index '); }Else{ Echo"User name or password error";}
thinkphp Realization Login function