SELECT AES_DECRYPT()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ssusa
Forum Newbie
Posts: 1
Joined: Tue Sep 04, 2012 3:36 pm

SELECT AES_DECRYPT()

Post by ssusa »

Hey everyone,

this is my first problem that I have come across which I am really stuck on and can not find any solutions. I am currently trying to create a secure way of storing user passwords in the database using AES_ENCRYPT. I have succesfully inserted the encrypted password into the mysql database, however I can not retrieve the decrypted value from the database using the following code...

Code: Select all

	$SQLstring="SELECT AES_DECRYPT(password,'$key') FROM accounts WHERE username='$ac_username'";
	$QueryResult = $DBConnect -> query($SQLstring);
	$row = mysqli_fetch_array($QueryResult);
	echo $row[0];
	if ($row[0] == $ac_password){
		session_register($ac_username);
		session_register($ac_password); 
		header("location:account.php");
	}
	else {
		
	}
When I enter in the SQLstring in the phpmyadmin sql console it will try to return a value from the field "AES_DECRYPT(password,'$key')" for some reason, which returns NULL. I assume that means it is trying to find an actual field associated with the row that is selected.

Please someone help!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: SELECT AES_DECRYPT()

Post by social_experiment »

“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply