ClevelandSlim Posted July 14, 2008 Share Posted July 14, 2008 Hello, This is my first time posting here. I need a php file that when called to via GET url with variables, the php file will have to encrypt a password, whichj will be one of the variables. Then I need the resulting info written to a specific MySQL database table. So far this is what I have. php GET variables and write to database code... <?php $db=mysql_connect("localhost", "usrnm", "pswd") or die("Could not connect to localhost."); mysql_select_db("visitors", $db) or die("Could not find visitors."); // The above lines establishes a connection with the // database. Keep localhost as is unless something different // is mentioned by your sql host. usrnm is user name and pswd is // password. What I want to say is, copy these lines as they are // and just replace the required fields and it should connect. $querySQL = "insert into visinfo (d_name, d_email, d_city) values ($name, $email, $city)"; if(!$querySQL) error_message(sql_error()); // The above statement generates an error if you have setup the table in such a way that there should not be a duplicate entry. ?> I can see how that will work. But what I don't see in the above code is how to clarify which table the data will be written to. I NEED TO SPECIFY TABLE. Here is a bit of the code from the help file that encrypts the password with the correct encryption... /** * Formats a password using the current encryption. * * @access public * @param string $plaintext The plaintext password to encrypt. * @param string $salt The salt to use to encrypt the password. [] * If not present, a new salt will be * generated. * @param string $encryption The kind of pasword encryption to use. * Defaults to md5-hex. * @param boolean $show_encrypt Some password systems prepend the kind of * encryption to the crypted password ({SHA}, * etc). Defaults to false. * * @return string The encrypted password. */ function getCryptedPassword($plaintext, $salt = '', $encryption = 'md5-hex', $show_encrypt = false) { // Get the salt to use. $salt = JUserHelper::getSalt($encryption, $salt, $plaintext); // Encrypt the password. switch ($encryption) { case 'plain' : return $plaintext; case 'sha' : $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext)); return ($show_encrypt) ? '{SHA}'.$encrypted : $encrypted; case 'crypt' : case 'crypt-des' : case 'crypt-md5' : case 'crypt-blowfish' : return ($show_encrypt ? '{crypt}' : '').crypt($plaintext, $salt); case 'md5-base64' : $encrypted = base64_encode(mhash(MHASH_MD5, $plaintext)); return ($show_encrypt) ? '{MD5}'.$encrypted : $encrypted; case 'ssha' : $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext.$salt).$salt); return ($show_encrypt) ? '{SSHA}'.$encrypted : $encrypted; case 'smd5' : $encrypted = base64_encode(mhash(MHASH_MD5, $plaintext.$salt).$salt); return ($show_encrypt) ? '{SMD5}'.$encrypted : $encrypted; case 'aprmd5' : $length = strlen($plaintext); $context = $plaintext.'$apr1$'.$salt; $binary = JUserHelper::_bin(md5($plaintext.$salt.$plaintext)); for ($i = $length; $i > 0; $i -= 16) { $context .= substr($binary, 0, ($i > 16 ? 16 : $i)); } for ($i = $length; $i > 0; $i >>= 1) { $context .= ($i & 1) ? chr(0) : $plaintext[0]; } $binary = JUserHelper::_bin(md5($context)); for ($i = 0; $i < 1000; $i ++) { $new = ($i & 1) ? $plaintext : substr($binary, 0, 16); if ($i % 3) { $new .= $salt; } if ($i % 7) { $new .= $plaintext; } $new .= ($i & 1) ? substr($binary, 0, 16) : $plaintext; $binary = JUserHelper::_bin(md5($new)); } $p = array (); for ($i = 0; $i < 5; $i ++) { $k = $i +6; $j = $i +12; if ($j == 16) { $j = 5; } $p[] = JUserHelper::_toAPRMD5((ord($binary[$i]) << 16) | (ord($binary[$k]) << | (ord($binary[$j])), 5); } return '$apr1$'.$salt.'$'.implode('', $p).JUserHelper::_toAPRMD5(ord($binary[11]), 3); case 'md5-hex' : default : $encrypted = ($salt) ? md5($plaintext.$salt) : md5($plaintext); return ($show_encrypt) ? '{MD5}'.$encrypted : $encrypted; } } So that's that. I am at a point where I could use the first piece of code posted above, except I can't figure how to specify the table. And as far as the encrypting of the password... I am totally lost. Please help. All the best, ~Slim~ Oh... attached is the text file with all the code need for this file, I guess [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
fenway Posted July 15, 2008 Share Posted July 15, 2008 Your table is "visinfo" -- you can put in into any table you'd like. Quote Link to comment Share on other sites More sharing options...
ClevelandSlim Posted July 15, 2008 Author Share Posted July 15, 2008 This is the code I have tested, and it's not working. <?php $db=mysql_connect("myhostname", "myusername", "password") or die("Could not connect to localhost"); $encrypted_pass = md5($password); $username = "$customer_fname.' '.$customer_lname"; $querySQL = "insert into jos_users (name,email,username,password,registerDate) values ($name,$email,$username,$encrypted_pass,$start_date)"; if(!$querySQL) error_message(sql_error()); ?> I have to figure out why and I don't know where to start. All the best, ~Slim~ Quote Link to comment Share on other sites More sharing options...
fenway Posted July 15, 2008 Share Posted July 15, 2008 Don't mean to point out the obvious, but I don't see any query() call. Furthermore, you're not single-quoting your variables in the VALUES(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.