return bin2hex(openssl_random_pseudo_bytes(32)); } // mcrypt_create_iv function mailuser($a) { mail($a[0], $a[1], implode("\r\n", $a[2]), 'From: do-not-reply@' . $a[3]); } if (!empty($_POST['username'])) { require_once INC_DIR . 'dbconn.php'; if (count($_POST) > 3) { // user creation if (preg_match("/^[\\w\\-.']{3,30}\$/", $_POST['username'])) { if (preg_match("/\\w+@[\\w-]+\\.\\w{2,}/", $_POST['email'])) { if (strlen($_POST['pass']) > 5 && $_POST['pass'] == $_POST['passconf']) { $mail = $_POST['email']; $salt = genRand(); $pass = mkPass($salt, $_POST['pass']); $token = $db->mkToken(); $res = $db->insert(array('created' => $db->prop('NOW()'), 'name' => $_POST['username'], 'email' => $mail, 'pass' => $pass, 'salt' => $salt, 'token' => $token)); if ($res) { $subj = "Welcome to the members of {$host}, " . $_POST['username']; $msg = array('To activate your new account please follow this link:', 'http://' . $host . '/login?token=' . $token, '', 'Best wishes,', $host); mailuser(array($_POST['email'], $subj, $msg, $host)); showAlert("Account created successfully. An e-mail has been sent to {$mail} with activation code.", $res); } else { showAlert(ucfirst(preg_replace("/.+'(.+)'.+'(.+)'/", '$2 $1 is already registered', $mysqli->error))); } } else { showAlert('Passwords must match and be over 5 symbols long'); } } else {
function mkToken() { $tkn = genRand(); while ($this->getRow($tkn)) { $tkn = genRand(); } return $tkn; }