Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement web2py password encryption in PHP?
    text
    copied!<p>I have a website that I am transforming from web2py to PHP, I am using the website database, so in the PHP site I have a login form that I am using and after the email and password are posted I check the database but I can't get the same encryption as the database password Field in the table auth_user? how can I do the same encryption that web2py dose?</p> <p>My PHP code is like this, but am using MD5:</p> <pre><code>&lt;?php // IF The Login Form Was Filled and Submited if(isset($_POST['email']) &amp;&amp; isset($_POST['password'])){ // Fetch The Username And Password $username = $_POST['email']; $password = $_POST['password']; // Use Md5 Hashed Password For Security $password_hash = md5($password); // Check IF The Username and Password was Not Empty . if (!empty($username) &amp;&amp; !empty($password)) { // Selecting The ID for the user with the Posted Credintials . $query = "SELECT id FROM auth_user WHERE email='$username' AND password='$password_hash' "; // Run The Query $query_run = mysql_query($query); // Check if the Query Works and return records . if ($query_run){ // Check if the Query Returns any rows $query_num_rows = mysql_num_rows($query_run); // If the query Dosent return any rows that means that the user credintials is wrong or the user is not registerd if ($query_num_rows == 0) { echo "&lt;div class='alert alert-error' style='width:300px;margin:0 auto'&gt;&lt;button type='button' class='close' data-dismiss='alert'&gt;&amp;times;&lt;/button&gt;&lt;h4&gt;Warning!&lt;/h4&gt;Invalid username / password combination&lt;/div&gt;&lt;br&gt;"; // If the Query Return a row that means that everyhting is right. } else if ($query_num_rows == 1) { // Fetch the user id from the query $user_id = mysql_result($query_run, 0 ,'id'); // Store the user id in the Session // Note : The Session is Started in the page Core.inc.php which is included to the index page and has session.start(); $_SESSION['user_id'] = $user_id; // Redirect To index Page , we user here the http_referer //which is coming from the core.inc.php that return the url of the page we came from header('Location: ' . '../index.php'); } else { echo "Who The Hell Are you !!"; } // If the Query Didnt Run Retrun mysql Error. } else{echo mysql_error();} // IF The Login Form Was Not Filled . } else { echo "&lt;div class='alert alert-error' style='width:300px;margin:0 auto'&gt;&lt;button type='button' class='close' data-dismiss='alert'&gt;&amp;times;&lt;/button&gt;&lt;h4&gt;Warning!&lt;/h4&gt;Sorry , You must Supply a username and a password . &lt;/div&gt;&lt;br&gt;"; } } // Print Out Any Other Errors if(mysql_error()){ echo "Database Error : " . Mysql_error(); } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload