Encrypting values

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
dakkonz
Forum Commoner
Posts: 69
Joined: Sat Dec 27, 2003 2:55 am
Location: Asia

Encrypting values

Post by dakkonz »

How can i encode and decode my values to be stored inside the Mysql database?? I get an error call to undefined function when i used AES_ENCRYPT or ENCODE().....
How is the code to be writter??
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

How are you using the code which is not working?

Mac
dakkonz
Forum Commoner
Posts: 69
Joined: Sat Dec 27, 2003 2:55 am
Location: Asia

Post by dakkonz »

Code: Select all

$query = "INSERT INTO song (songname) VALUES (ENCODE('$sn'))";
	$result = @mysql_query ($query);
Is this correct??

thanks
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Post by partiallynothing »

I have not heard of an 'encode' function, although there may be, but one i do know of is 'password', but i would not recommend it. When you do it the way you are, you are sending the information unencrypted (or un-hashed) and then mySQL does the hashing. To encode the string before it is sent, use something like MD5 hashing. Here is an example:

Code: Select all

<?php
$my_hashed_string = md5($my_unhashed_string);

$query = "INSERT INTO song (songname) VALUES ('$my_hashed_string')";
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

encrypt and decrypt, not as secure as MD5 but can be reversed back into plain text unlike MD5
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

or you could make some crazy function to encrypt with

Code: Select all

function crypto($str)
{
    $str = crypt($str);
    $str = md5($str);
    $str = md5($str);
    $str = "9Fq5tG3".$str."GT9c8XkkwWal58p";
    return $str;
}
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

dull, it's much easier to decrypt the string encrypted twice =)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i know that but rather then decrypting when you want to compare an excrtpted string to a non encrypted one all you have to do is use the same func to encrypt the non encrypted one then compare them.....
dakkonz
Forum Commoner
Posts: 69
Joined: Sat Dec 27, 2003 2:55 am
Location: Asia

Post by dakkonz »

kz will try it out and get back to here....thanks
Post Reply