Fixxer Posted July 9, 2006 Share Posted July 9, 2006 If I store the information using the MD5 function, how do I use php to convert it back to normal when I want to check a login? I used myphpadmin to convert it to MD5.Also, what would I put for local host, my domain name? Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/ Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 This is the whole point of MD5 , that you cannot reverse engineer it.What you do is you store the MD5 informtion somewhere.Then, when the user enters their login, you MD5 it and check if it is equal to the previous one.So, if there is a field called PASSWORD in your table, you could do this to check it against what someone entered in a form:[code]$pass = $_POST['pass'];$md5Pass = md5($pass);$sql = "SELECT * FROM table WHERE PASSWORD='$md5Pass' ";$result = mysql_query($sql);[/code]I left some things out like DB connection etc. but it should get your started. Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55100 Share on other sites More sharing options...
.josh Posted July 9, 2006 Share Posted July 9, 2006 as far as your 2nd question: in most cases, your local host can simply be "localhost" if that doesn't work, then yes, you will have to put your database server. Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55107 Share on other sites More sharing options...
Fixxer Posted July 9, 2006 Author Share Posted July 9, 2006 Ok am trying this code, but so far no login![code]<?php$dbHost = "localhost";$dbUsername = "edited";$dbPassword = "edited";$dbName = "Xiemsoft_Site";#$username = $_POST['user'];#$password = $_POST['pass'];$username = "testname";$password = "testpass";$md5Password = MD5($password);$link = mysql_connect($dbHost,$dbUsername,$dbPassword);mysql_select_db($dbName,$link);$SQL = "SELECT username FROM webhosting WHERE username = \"$username\" AND password = \"$md5Password\"";$result = mysql_query($SQL,$link);if(mysql_num_rows($result) == 0){ $message = "Invalid Login.";}else{ $message = "Logged In!";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55121 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 Your problem might be that MySQL wants string surrounded by single quotes, not double quotes. Make sure you have an "or die" clause on all your mysql functions that might cause an error.[code]<?php$db_host = "host";$db_user = "name";$db_pass = "pass";$db_name = "name";$pass = "name"$username = "pass"$link = mysql_connect($db_host, $db_user, $db_pass) or die("Couldn't connect to the database<br>" . mysql_error());mysql_select_db($db_name, $link) or die("Couldn't select database<br>" . mysql_error());$query = "SELECT username FROM webhosting WHERE username = '$username' AND password = '$pass' ";$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());if(mysql_num_rows($result) == 0){ $message = "LOSER";}else // the number of rows is either going to be zero or one, so you only need the else here{ $message = "WINNER";}?><html><head><title>TEST</title></head><body>TESTING 123...<?php echo $message; ?></body></html>[/code]Whenever you're debugging, make sure the error reporting is set to the maximum by putting this at the top of your script:[code]<?php// Report all PHP errors (bitwise 63 may be used in PHP 3)error_reporting(E_ALL);?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55123 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 You're right, at the top of all your files you should put this:[code]error_reporting(E_ALL);[/code]Because PHP should have thrown an error on the SQL line because of your use of double quotes inside a double quotes string. Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55128 Share on other sites More sharing options...
Fixxer Posted July 9, 2006 Author Share Posted July 9, 2006 Ahh thanks, it appears that I cannot connect :xCouldn't connect to the databaseCan't connect to local MySQL server through socket '/tmp/mysql.sock' (46) Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55129 Share on other sites More sharing options...
Fixxer Posted July 9, 2006 Author Share Posted July 9, 2006 Does anyone know what that means? Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55249 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 It most likely means that your mysql database is not up.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55250 Share on other sites More sharing options...
Fixxer Posted July 9, 2006 Author Share Posted July 9, 2006 It is, i created it using phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-55297 Share on other sites More sharing options...
Fixxer Posted July 12, 2006 Author Share Posted July 12, 2006 Bump Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-56797 Share on other sites More sharing options...
Fixxer Posted July 17, 2006 Author Share Posted July 17, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/14088-questions-about-mysql/#findComment-59625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.