TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-07-2008, 10:09 PM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default Loggining ( password and encryption )

Now, if you make a login system.. You want encryption for the users password, yes we all know. But thing is, if you encrypt it, such as with the md5() function algorithm, wouldn't that make it incorrect, if a user tries to login, and is trying to access his password which has now been encrypted. My problem is this, I try to encrypt passwords when registering, in the sql, and well, I go to login, and it gives me an error which I set, invalid password, please try again, well I know you cannot DECRYPT the password, so basically your account is stuck. :[

Would I just go by doing a base64 encryption? and then decrypt it?? Though that's a security risk it sounds, bleh.. Help with this please.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-07-2008, 10:12 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

You can encode the password before performing the check, you know?

PHP Code:
$user $_POST['username'];
$pass md5($_POST['password']);

mysql_query"SELECT id FROM users WHERE username='{$user}' AND password='{$pass}'" ); 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-07-2008, 10:14 PM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
You can encode the password before performing the check, you know?

PHP Code:
$user $_POST['username'];
$pass md5($_POST['password']);

mysql_query"SELECT id FROM users WHERE username='{$user}' AND password='{$pass}'" ); 
Bah, lemme try this.

I forgot this method, >.<
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-07-2008, 11:09 PM   #4 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

You can also do the following

PHP Code:
$user $_POST['username'];
$pass $_POST['password'];

mysql_query"SELECT id FROM users WHERE username='$user' AND password = PASSWORD('$pass')" ); 
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
The Following User Says Thank You to Rendair For This Useful Post:
Orc (02-07-2008)
Old 02-07-2008, 11:10 PM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

What does that function do?
sql Code:
password = PASSWORD('$pass')"

My brain is all over today. :/
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-07-2008, 11:19 PM   #6 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

Well you can insert data into the table using that and it encrypts the password and then you use it again in a select to un-encrypt it.
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 02-07-2008, 11:25 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

A key security point is that you should not be able to decrypt passwords! Use one-way hashing (MD5, SHA*, etc) and then compare the supplied password with the hashed password in the database.

Orc, the PASSWORD is another hashing function like MD5 and behaves in much the same way, just using a different algorithm to get the final hashed value.
Salathe is offline  
Reply With Quote
Old 02-08-2008, 06:44 PM   #8 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Just to throw another idea on to the pile, you could always take the vBulletin route and use Javascript to MD5() the password before you send it to your PHP script using one of the many javascript MD5 implementations available.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-09-2008, 12:40 AM   #9 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Just to throw another idea on to the pile, you could always take the vBulletin route and use Javascript to MD5() the password before you send it to your PHP script using one of the many javascript MD5 implementations available.

Alan
Now, why would you want to do that? JS can be easily sniffed, so don't check passwords and other sensitive information through JS. You can MD5 the password from the script, or directly from the query if you need to:

Code:
SELECT id FROM  users WHERE username='username' AND password=MD5('password')
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-09-2008, 08:24 AM   #10 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

The idea behind it is to use a salt with your passwords. You then MD5 the password using JS, send it to your PHP script, the PHP script then adds the salt and md5's the whole lot again, then compares it against your password table.

The theory being that the plain-text password is never transmitted across the internet.

Edit: Think of it this way, in my scenario, if someone sniffed the password, they would end up with an MD5 hash of it. They could then either try to match the hash until they found the original password, or brute force your script until they found the salt. In your scenario, if someone sniffed the password, they would end up with the plain-text password for the user.

Alan

Last edited by Alan @ CIT : 02-09-2008 at 08:31 AM. Reason: Added usage scenario
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:04 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design