Encrypting password..Please help!!

Alles, was PHP betrifft, kann hier besprochen werden.

Encrypting password..Please help!!

Postby arjita » 07. August 2007 22:31

Hi All,

I am trying to encrypt a password that the user enters ,and then compare it to a hard coded value.I want that when the user types in the passwords it appears like stars/dots ..like in a generic login page.

$password =md5($_POST['password']);
(I tried using the crypt function aswell..doesnt help :()

and then

if ($password == "Arjita").

Pleaseeee help! :cry:

Thanks in advance
arjita
 
Posts: 6
Joined: 17. July 2007 20:35

Postby Wiedmann » 07. August 2007 23:15

It make no sense to store an encrypted string (the entered password) in a variable, and then compare this variable with an unencrypt string (hardcoded password). This can't work.
--> The hardcoded password must also be encrypted. (or use the entered password unencrypted)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby arjita » 09. August 2007 22:03

I know..But I am not sure how to do it.I would want to encyprt the hardcoded password then to enetered the password unencrypted.

Thanks
arjita
 
Posts: 6
Joined: 17. July 2007 20:35

Postby glitzi85 » 09. August 2007 22:10

Hello Arjita,

it is not possible to encrypt an md5-crypted hash (maybe if you work for the NSA and have enough time). That's the sense of the Oneway Hashing Functions.

You should save the crypted password in a file, Database or even in your PHP-File, crypt the entered passwort and compare it with the saved password.

Code: Select all
<?php
$password = "0993c6f9e49d8f505d0667274ff4f2fe";
if(md5($_POST['password']) == $password){
 echo "Welcome Arjita";
}else{
 echo "You are not Arjita";
}
?>


In this case nobody can log in even if he know the upper String (0993...).

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim


Return to PHP

Who is online

Users browsing this forum: No registered users and 24 guests