Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['email']) && !empty($_POST['secret'])) {
- if ($_POST['secret'] != 'vwevqiwubevoqwyev12930v1273vwoievbqwoeivgdfgdyeiVBYWOVEQOPB') {
- die('?');
- }
- ########################
- $db_ip = "";
- $db_user = "";
- $db_password = "";
- $db_auth = "auth";
- ########################
- $username = htmlspecialchars($_POST['username']);
- $password = htmlspecialchars($_POST['password']);
- $email = htmlspecialchars($_POST['email']);
- echo register_user($username, $email, $password);
- }
- function connect($ip, $user, $password, $database){
- $con = mysqli_connect($ip, $user, $password, $database) or die('try again in some minutes, please');
- if (!$con)
- printf("Connect failed: %s\n", mysqli_connect_error());
- else
- return $con;
- }
- function encrypt($username, $password)
- {
- $password = sha1(strtoupper($username) . ":" . strtoupper($password));
- $password = strtoupper($password);
- return $password;
- }
- function check_user_exist($username){
- global $db_ip, $db_user, $db_password, $db_auth;
- $con = connect($db_ip, $db_user, $db_password, $db_auth);
- $stmt = $con->prepare("SELECT * FROM account WHERE `username`=?");
- $stmt->bind_param("s", $username);
- $stmt->execute();
- $stmt->store_result();
- return $stmt->num_rows;
- $stmt->close();
- $con->close();
- }
- function check_email_exist($email){
- global $db_ip, $db_user, $db_password, $db_auth;
- $con = connect($db_ip, $db_user, $db_password, $db_auth);
- $stmt = $con->prepare("SELECT * FROM account WHERE `email`=?");
- $stmt->bind_param("s",$email);
- $stmt->execute();
- $stmt->store_result();
- return $stmt->num_rows;
- $stmt->close();
- $con->close();
- }
- function register_user($username, $email, $password){
- $new_password = encrypt($username,$password);
- $sql = "INSERT INTO `account` (`username`, `sha_pass_hash`, `email`) VALUES (?,?,?)";
- global $db_ip, $db_user, $db_password, $db_auth;
- $con = connect($db_ip, $db_user, $db_password, $db_auth);
- if (check_user_exist($username) > 0)
- return 1;
- if (check_email_exist($email) > 0)
- return 2;
- if (check_user_exist($username) == 0 && check_email_exist($email) == 0) {
- if ($stmt = $con->prepare($sql)) {
- $stmt->bind_param("sss", $username, $new_password, $email);
- $stmt->execute();
- $stmt->close();
- return 3;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement