473,379 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Sha1 encryption and posting login details to mysql database

1
i have encrypted admin passwords in mysql, now i want to make the login page work. but my code seems to be failing to login. please help:
here is my .php file to connect and make validation:
Expand|Select|Wrap|Line Numbers
  1. mysql_connect($host,$user,$pass);
  2.  
  3.         mysql_select_db($db);
  4.  
  5.  
  6.         if (isset($_POST['admin']) || ($_POST['password'])) {
  7.  
  8.  
  9.             $password = $_POST['password'];
  10.  
  11.  
  12.         $sql =     "SELECT * FROM admin WHERE password = SHA1('$password')";
  13.  
  14.  
  15.         $result = mysql_query($sql);
  16.  
  17.         if (mysql_num_rows($result)==1) 
  18.         {
  19.  
  20.             header("Location: admin.php");
  21.  
  22.         } else {
  23.  
  24.  
  25.             echo "<h1>Invalid Login Information</h1>";
  26.         }
  27.         }
  28.  
  29.     ?>
Apr 14 '15 #1
2 1599
Hii gmag,
First of all make sure whether you are encrypting your password in database or not. You will have to encrypt your password in database using SHA1 Method then if your both POST password and database password is in encrypted by sha1 then match will be done.
Apr 15 '15 #2
Luuk
1,047 Expert 1GB
If multiple users have the same password,
than line #17 will break your program......

To test your script:
add a line 'echo $sql;' after line #12

verify if:
SELECT '<yourpassword>', sha1('<yourpassword>');
matches with the result....
(change <yourpassword> with your password.... ;)
Apr 15 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: paul | last post by:
Hi everyone, I've just started using php, and although I am very impressed by it, there are some things with which I am confounded! What I'm trying to do is read in a Date from a mySql database...
0
by: mdh | last post by:
I am trying to learn the basics of MVC applications using a Tomcat infrastructure. I'm starting by building a simple application with: * a login.jsp page for a basic login form with a action...
3
by: Xerxes | last post by:
Hi, I would like to import the tables from MySQL database into Access database and I am not sure how to go about it. I tired to "Import External Data" from Access, selected "ODBC database" from...
6
by: Bob Sanderson | last post by:
I have created a MySQL database for my company which is accessed by PHP pages. I would like to permit some users to edit the records but allow others read-only access. However, I don't want to have...
2
by: damod.php | last post by:
what's the Basic Encryption method used in mysql, whats iner join whats outer join ,diff b/w.what are the encryption methods used to encrypt the user name and password.in php/mysql
9
by: Ben | last post by:
Hello, I'll bet this has been asked a million times but I can't seem to find a thread that gives the clear example I need. This PC has MySQL and IIS configured and running. The MySQL database is...
2
by: vb2005matt | last post by:
i have just learned how to connect to a remote MySQL database, i need to search this database by the login field, find the desired login field, and display the users information in textboxes. The...
4
by: peridian | last post by:
Hi, I've been googling all over to try and get this to work, but no luck. I have two Linux servers, one Apache and one MySQL. I have put phpMyAdmin on the web server, and configured it to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.