Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 28th November 2007, 22:37
igongora igongora is offline
Junior Member
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP authentication with mysql encrypt function

Hi,

I have a mysql table where I store passwords using mysql encrypt function, and I would like to be able to create a login script where I can type in login and password and then it will authenticate my user. However, whenever I try to encrypt the password I get a new character string, how can I acheive my goal without changing encrypt by md5 or other similar.

Regards,
Reply With Quote
Sponsored Links
  #2  
Old 29th November 2007, 16:51
Mosquito Mosquito is offline
Member
 
Join Date: Nov 2006
Posts: 85
Thanks: 5
Thanked 6 Times in 5 Posts
Default

Assuming you have only a Text Field for User name and password - named 'username' and 'password',

To verify login:
Code:
$query = "SELECT username, password, other_fields FROM users_table WHERE username = $_REQUEST['username'] AND password = encrypt($_REQUEST['password'])";
$result = mysql_query($query) or die('Query failed: ' . mysql_error()); 

if (mysql_num_rows($result) == 1)
{
	//successful login
}
else
{
	// not successful
}
I just wrote this code up now, so I haven't tested it. However, it should work with few modifications. What this script does it make sure only 1 row is returned (matching username and password...hopefully those are unique on your database). The query itself, will use the MySQL encrypt() function to compare the input password to what is in the database.

If you have PHP/MySQL questions, take a look at
http://php.net/mysql

Last edited by Mosquito; 29th November 2007 at 16:54.
Reply With Quote
  #3  
Old 29th November 2007, 19:08
igongora igongora is offline
Junior Member
 
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks moskito,

but it did not work, th eporblem I have is that encrypt retunrs each time an encrypted string differetne form the previous so the passwords do not match.

for instance:
SELECT encrypt('abc') as string FROM `users` LIMIT 1
Z9Uu2KHZiz/6Y
SELECT encrypt('abc') as string FROM `users` LIMIT 1
HAgC9F0JjlOCE

The passwords never match..
regards,
Reply With Quote
  #4  
Old 29th November 2007, 21:46
Mosquito Mosquito is offline
Member
 
Join Date: Nov 2006
Posts: 85
Thanks: 5
Thanked 6 Times in 5 Posts
Default

How are you inserting these into the database? Are you using a salt? Or did you use the MySQL PASSWORD() function on the insert? If you did the latter, change the ecrypt() calls in my above code to password().
Reply With Quote
  #5  
Old 17th February 2009, 11:10
bvidinli bvidinli is offline
Junior Member
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

goto mysql console, type:
select encrypt('aaa','aa');

i think you will be able to get same string with encrypt('string','salt')
this way, you will be able to store and match passwords in mysql database..
hope this helps,
let me know if this worked..
Reply With Quote
  #6  
Old 13th August 2011, 21:16
new new is offline
Junior Member
 
Join Date: Aug 2011
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
Default encrypt function in registration form

Moskito, verify login works, but I Wonder how ..?

I did follow Falko's tutorial Here... and everything works perfect, the only thing that I dont get.. is how to:

Make register form that match the "encrypt".

I have posted a question in ubuntu forums ( here )... But dont get any result.

If I type (in my server terminal):
PHP Code:
mysql -u root -p
####  password here
USE mail;
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('my@site.com'ENCRYPT('PassGoHere'), 10485760);
quit
works perfect, but how to insert these values (from a PHP) registration from???

I have not idea... how to make my registration form >>> to insert "ENCRYPT" password, like I do in my server terminal.

regards.

Last edited by new; 13th August 2011 at 21:18.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 10:29
Slightly Confused (DNS & Server Help) JohnnyBGoode Installation/Configuration 26 14th August 2007 10:54
Apache2 Freezes celtic Server Operation 31 28th May 2007 18:18
SuSE Enterprise, PHP binary coming with ISPConfig does not work properly NexusTechUS Installation/Configuration 1 26th April 2007 21:03


All times are GMT +2. The time now is 08:18.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.