Logon password comparison questions

Source: Internet
Author: User
The database storage field is md5 (password), and the form receiving and processing password is md5 (password + suffix). do the two statements return true logic values? Why did I try it last night? the returned account password is incorrect, but the ajax return value is OK. if all the input is not correct, ajax returns null. If the password stored in the password... database is md5 (password) and the password for receiving the form is md5 (password + suffix), are the returned logical values true? Why did I try it last night? the returned account password is incorrect, but the ajax return value is OK. if all the input is not correct, ajax returns null. If the password does not match, why does ajax return OK? Why is the returned Password incorrect? Where is the problem?
1. IndexController. class. php:


  Display ();} public function checkUserName () {if (! IS_AJAX) {$ data = array ('errmsg '=> 'illegal access method');} $ userName = I ('username', '', 'htmlspecialchars '); $ userPass = I ('userpass', '', 'htmlspecialchars'); $ userInfo = D (" Stuser ")-> getUserInfo ($ userName ); if ($ userInfo ['userpass']! = HandleMd5Pass ($ userPass) {// echo $ userInfo ['userpass']."
"; // Echo handleMd5Pass ($ userPass); echo" incorrect user name or password "; // var_dump (handleMd5Pass ($ userPass);} if ($ userInfo) {// $ userInfo-> where (array ('id' => $ userInfo ['id'])-> save ($ errMsg); session ('userid ', $ userInfo ['id']); $ data = array ('info' => 'OK', 'callback' => U ('/stfjzd-13/index. php/Home/Index/index');} $ this-> ajaxReturn ($ data );}}

2. StuserModel. class. php


  DB = M ("Stuser");} // retrieve user data in the database, find () to retrieve one-> Index public function getUserInfo ($ userName) {// $ res = $ this-> DB-> field ('username', 'userpass')-> where ('username = "'. $ userName. '"')-> find (); $ userInfo = $ this-> DB-> where ('username = "'. $ userName. '"')-> find (); echo $ this-> DB-> getLastSql (); return $ userInfo ;}}?>

3. Login. js

$ ('. Search_sub '). click (function (event) {event. preventDefault (); var userName = $ ("# username "). val (); var userPass =$ ("# userpass "). val (); if (userPass = "" | userName = "") {alert ("login name and password cannot be blank "); $ ("# username "). focus (); return false;} else {var url = "/stfjzd-13/index. php/Home/Index/checkUserName "; // var url =" {U ('/stfjzd-13/index. php/Home/Index/checkUserName ')} "; $. post (url, {username: userName, userpass: userPass}, function (msg) {if (msg. errMsg = "OK") {window. location. href = msg. callback;} else {alert (msg. errMsg) ;}}, "JSON ")}})

Reply content:

The database storage field is md5 (password), and the form receiving and processing password is md5 (password + suffix). do the two statements return true logic values? Why did I try it last night? the returned account password is incorrect, but the ajax return value is OK. if all the input is not correct, ajax returns null. If the password does not match, why does ajax return OK? Why is the returned Password incorrect? Where is the problem?
1. IndexController. class. php:


  Display ();} public function checkUserName () {if (! IS_AJAX) {$ data = array ('errmsg '=> 'illegal access method');} $ userName = I ('username', '', 'htmlspecialchars '); $ userPass = I ('userpass', '', 'htmlspecialchars'); $ userInfo = D (" Stuser ")-> getUserInfo ($ userName ); if ($ userInfo ['userpass']! = HandleMd5Pass ($ userPass) {// echo $ userInfo ['userpass']."
"; // Echo handleMd5Pass ($ userPass); echo" incorrect user name or password "; // var_dump (handleMd5Pass ($ userPass);} if ($ userInfo) {// $ userInfo-> where (array ('id' => $ userInfo ['id'])-> save ($ errMsg); session ('userid ', $ userInfo ['id']); $ data = array ('info' => 'OK', 'callback' => U ('/stfjzd-13/index. php/Home/Index/index');} $ this-> ajaxReturn ($ data );}}

2. StuserModel. class. php


  DB = M ("Stuser");} // retrieve user data in the database, find () to retrieve one-> Index public function getUserInfo ($ userName) {// $ res = $ this-> DB-> field ('username', 'userpass')-> where ('username = "'. $ userName. '"')-> find (); $ userInfo = $ this-> DB-> where ('username = "'. $ userName. '"')-> find (); echo $ this-> DB-> getLastSql (); return $ userInfo ;}}?>

3. Login. js

$ ('. Search_sub '). click (function (event) {event. preventDefault (); var userName = $ ("# username "). val (); var userPass =$ ("# userpass "). val (); if (userPass = "" | userName = "") {alert ("login name and password cannot be blank "); $ ("# username "). focus (); return false;} else {var url = "/stfjzd-13/index. php/Home/Index/checkUserName "; // var url =" {U ('/stfjzd-13/index. php/Home/Index/checkUserName ')} "; $. post (url, {username: userName, userpass: userPass}, function (msg) {if (msg. errMsg = "OK") {window. location. href = msg. callback;} else {alert (msg. errMsg) ;}}, "JSON ")}})

If ($ userInfo ['userpass']! = HandleMd5Pass ($ userPass) {// only the error is returned, but not to the front-end. Echo "incorrect user name or password"; // var_dump (handleMd5Pass ($ userPass);} if ($ userInfo) {// your code runs here, user name pair, so userInfo is found, so OK is returned. If the password is correct, it should be returned to the front-end when the password verification is incorrect. the session ('userid', $ userInfo ['id']) will not be run in the future. $ data = array ('info' => 'OK', 'callback' => U ('/stfjzd-13/index. php/Home/Index/index');} $ this-> ajaxReturn ($ data );

In comments

Echo "incorrect user name or password ";

Here return

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.