Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,177 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,170 people online right now. Registration is fast and FREE... Join Now!




password encryption

 
Reply to this topicStart new topic

password encryption, continuation of registration

Decypher
29 Aug, 2008 - 12:29 PM
Post #1

New D.I.C Head
*

Joined: 28 Jun, 2008
Posts: 44

ok good news or bad news?

The good news is I would like to say thank you to everyone who helped me as I now have a working register form

HOWEVER,

when the password gets encrypted it saves as a very long number/letter phrase any suggestions?
User is offlineProfile CardPM
+Quote Post

Mcbazzo
RE: Password Encryption
29 Aug, 2008 - 12:33 PM
Post #2

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 37

Hi sorry im a bit further behind than you but could you help me, im usng wamp however I dont know where to put my codes. <?php ?> <-that.
User is offlineProfile CardPM
+Quote Post

Decypher
RE: Password Encryption
29 Aug, 2008 - 12:37 PM
Post #3

New D.I.C Head
*

Joined: 28 Jun, 2008
Posts: 44

QUOTE(Mcbazzo @ 29 Aug, 2008 - 01:33 PM) *

Hi sorry im a bit further behind than you but could you help me, im usng wamp however I dont know where to put my codes. <?php ?> <-that.


have a look on this if you're new to this:

http://www.w3schools.com/PHP/DEfaULT.asP
User is offlineProfile CardPM
+Quote Post

Mcbazzo
RE: Password Encryption
29 Aug, 2008 - 12:53 PM
Post #4

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 37

I have something like that all need to know is how to add codes and how to view my page, im using wamp
User is offlineProfile CardPM
+Quote Post

Decypher
RE: Password Encryption
29 Aug, 2008 - 01:01 PM
Post #5

New D.I.C Head
*

Joined: 28 Jun, 2008
Posts: 44

Obviously it has something to do with
CODE
$_POST['pass'] = md5($_POST['pass']);


is there any other way of encrypting the passwords without this?
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Password Encryption
29 Aug, 2008 - 01:29 PM
Post #6

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 862



Thanked: 89 times
Dream Kudos: 50
My Contributions
In general, you do not encrypt passwords, you hash them, which is what you are doing here.

When a user attempts to log in, you hash the value provided by the user -- as you did before you saved it -- and compare it to the hashed value stored in your database. Ideally you would salt the data prior to saving it initially, so that a rainbow attack is more difficult...use Google for info on salts and hashes, and try to avoid getting hungry at the same time.

Also, I'm not fond of what you're doing here, with the inline modification of the POST array. You should use a temporary variable to hold the value of the hashed password, rather than overwriting what's in the array.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Password Encryption
29 Aug, 2008 - 06:50 PM
Post #7

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
yes, some login systems use $_POST['pass'] as a variable... *shrugs* you can do it, just one way or another...

As for what I said in the other thread, some forums use this: sha1(strtolower($username).$password);
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Password Encryption
29 Aug, 2008 - 06:51 PM
Post #8

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 481



Thanked: 32 times
My Contributions
QUOTE(JackOfAllTrades @ 29 Aug, 2008 - 02:29 PM) *

When a user attempts to log in, you hash the value provided by the user -- as you did before you saved it -- and compare it to the hashed value stored in your database.

Sorry to horn in, but this has me wondering about a technique I'm trying.

I know that your way is the accepted way of doing it, but I'm wondering if it's really necessary. Since it's all happening server side anyway, and the user's password has to get to the server before it can be hashed, is there anything wrong with grabbing the password from the user and the database and comparing them? I'm not talking about doing it the way that (it appears) that others have done it. I'm talking about looking up the password by using the username. To block any insertion techniques, I still hash the password, so I'm wondering if this could have some vulnerability that I'm overlooking.

Here's some of my code:
CODE
if (($_POST['UName'] != "") and ($_POST['UPass'] != "")){
mysql_connect("127.0.0.1", "root", "mypassword") or die(mysql_error()); // Connect to database & table.
mysql_select_db("mydatabase") or die(mysql_error()) or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
$UN=$_POST['UName'];
$users = mysql_query("SELECT * FROM Security WHERE Username = '$UN'") or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
$thisuser = mysql_fetch_array( $users );
mysql_close();
$loginsalt = md5($_POST['UPass'].$thisuser['salt']);
$actualsalt = md5($thisuser['Psswrd'].$thisuser['salt']);

if ($loginsalt == $actualsalt) {
$_SESSION['logname'] = $thisuser['Username'];
$_SESSION['pwd'] = $thisuser['Psswrd'];
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=accessgranted.php">';
}
}



User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Password Encryption
29 Aug, 2008 - 07:59 PM
Post #9

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
if i'm reading that correctly, you'd let the person choose his own salt? it's an interesting way to do it, and it's still secure.

I'd say go for it if that's what you want to do, there's no "real" method to do it.
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Password Encryption
30 Aug, 2008 - 05:23 AM
Post #10

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 481



Thanked: 32 times
My Contributions
QUOTE(JBrace1990 @ 29 Aug, 2008 - 08:59 PM) *

if i'm reading that correctly, you'd let the person choose his own salt?

Actually, I don't! I randomly generate a salt when the user is added. They never see it.

My feeling is that most php insertion attacks rely on using user supplied information to lookup or modify information in the database, so I try not to rely on that information. I get the username and password from the user, look them up according to their username, read the password from the database and hash it with the salt that I've previously left in the database. Then I hash the password they supplied with the same salt. If the two hashes match, they're allowed in. It works, but I'm trying to figure out if there is an exploitable weakness somewhere that I'm not seeing. ph34r.gif

User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Password Encryption
30 Aug, 2008 - 05:41 AM
Post #11

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
the salt would be from a database, so it's not quite an exploit as an ok idea. Generally, it's not too bad, and it actually sounds like it would work.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:40AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month