php - To select the encrypted password from mysql -
I have to select only the password from the table, with the specific username entered via the login form. I store passwords in encrypted form in mysql table. So I need to compare the given passwords and stored passwords and print "login successfully". The other password is wrong. This is my code. Now I am getting the output as "1 resource id # 4". Any one plus help ...
mysql_select_db ($ dbName); $ User_name = $ _ post ['name']; $ Pswd = $ _ Post ['pswd']; $ Res = mysql_query ("Select from xxx * where name = '$ user_name'"); $ Line = mysql_num_rows ($ res); Echo per line; $ Encaps = mysql_query ("Select password xxx where name = '$ user_name'"); $ Result1 = mysql_fetch_array ($ Encash); $ Result1 return; If ($ line & gt; 0) {// resonance 'hi'; If (MD5 ($ pswd) == $ Result 1) {echo 'hi'; Echo "You have successfully signed in !!!"; // resonance $ name = $ line ['name']; //header("location:check.html "); }} Else resonant "you are not a member";
You're disturbing it. You do not have to retrieve the password from the database. You need to see if you can select the line in which the user name and password have been submitted.
First - get the user name and password from the user and get them in the form that you have stored.
$ username = $ _POST ['name']; $ Password = my_password_encryption_function ($ _POST ['pswd']);
Second - Set up your SQL Use a prepared statement to protect against attacks of SQL injection. Your current view is insecure and allows users to change the password of brain users (among other things).
$ location created = $ db-> Ready (choose from 'xxx where name =: name and password =: password'); $ Ready: Setting-> Execution (array (': name' = & gt; $ user name, ': password' = & gt; $ password)); $ Rows $ are ready for foundation- & gt; Fatch ALL ();
Third - Just return the rows. If you get a result, the password matches. If you get zero results, then the password does not match.
Comments
Post a Comment