Jump to content

xExekut3x

Members
  • Posts

    3
  • Joined

  • Last visited

xExekut3x's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm using MySQL to store Session data. I understand that "session_start();" has to be called before anything else. Are there no exceptions? Can I not open up a database connection and pass it to my Session class before I call session_start();? I'm trying to cut down on the number of times I open up SQL connections in my script, and if I could open up just one connection per user, that would be great.
  2. Forgot to add - I'm using XAMPP 1.8.2 which uses MySQL 5.5.32.
  3. I'm using PHP mcrypt to encrypt data, specifically passwords. The Encryption works fine, I'm guessing. I can encrypt and decrypt data just fine, at least, but I'm having issues storing it in MySQL. Let me post some information. Here is my MySQL structure. CREATE DATABASE db CHARACTER SET utf8 COLLATE utf8_unicode_ci ; use db ; CREATE TABLE IF NOT EXISTS `test` ( `id` int(15) unsigned zerofill NOT NULL AUTO_INCREMENT, `password` char(32) COLLATE utf8_unicode_ci NOT NULL, `password_key` char(128) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; Here is my encryption class. class Encryption { private $_cipher, $_mode, $_hash, $_salt; public function __construct($cipher = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_ECB, $hash = 'sha512') { $this->_cipher = $cipher; $this->_mode = $mode; $this->_hash = $hash; $this->_salt = 'K~1[G50*?2GV42I.47517Oe67>WOZw=l'; } public function encrypt($data, $key) { $key = hash($this->_hash, $this->_salt . $key . $this->_salt); $key = substr($key, 0, mcrypt_get_key_size($this->_cipher, $this->_mode)); $iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypt = mcrypt_encrypt($this->_cipher, $key, $data, $this->_mode, $iv); return $crypt; } public function decrypt($data, $key) { $key = hash($this->_hash, $this->_salt . $key . $this->_salt); $key = substr($key, 0, mcrypt_get_key_size($this->_cipher, $this->_mode)); $iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypt = mcrypt_decrypt($this->_cipher, $key, $data, $this->_mode, $iv); return $decrypt; } } I use this to create the key. $key = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); My maximum password length is 30 characters, and any password between 8-30 characters always outputs 32 characters. As you can see, my password field is 32 characters. Everything gets put into the database just fine except the password. Using this method I sometimes get crazy looking passwords such as what's in the image attached (I had to attach it because it wouldn't paste properly) Which is fine, in my opinion, but apparently my MySQL table doesn't like this format. I'm guessing utf8_unicode_ci si the wrong format. Anyone have any idea what the correct format is or any other suggestions?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.