Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //We connect to the database
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password="testdbpass"; // Mysql password
- $db_name="test"; // Database name
- // Connect to server via PHP Data Object
- $dbh = new PDO("mysql:host=localhost;dbname=test", $username, $password);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //Validation
- CRYPT_BLOWFISH or die ('No Blowfish found.');
- //This string tells crypt to use blowfish for 15 rounds.
- $Blowfish_Pre = '$2y$17$';
- // Blowfish accepts these characters for salts.
- $Allowed_Chars =
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
- $Chars_Len = 63;
- $salt = "";
- for($i=0;$i<45 ;$i++)
- {
- $salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
- }
- $bcrypt = $Blowfish_Pre . $salt;
- $password = crypt($_POST['password'] , $bcrypt) ;
- // Insert statements with PDO
- try {
- $query = $dbh->prepare("INSERT INTO `users` (username, email, fname, lname, password)
- VALUES (:username, :email, :first, :last, :password)");
- $query->execute(
- array(
- 'username' => $_POST['username'],
- 'email' => $_POST['email'],
- 'first' => $_POST['fname'],
- 'last' => $_POST['lname'],
- 'password' => $password
- ));
- }
- catch (PDOException $e) {
- error_log($e->getMessage());
- die($e->getMessage());
- }
- $dbh= null;
- ?>
- <html>
- <body>
- <p>
- Thank you for registering your account. Please wait for administrator approval before doing anything else. Thank you - System Administrator.
- </p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement