Guest User

Untitled

a guest
Mar 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // functions.php
  2. <?php include 'connect.php'; ?>
  3. function createData() {
  4. global $connection;
  5. $username = mysqli_real_escape_string($connection, $username);
  6. $password = mysqli_real_escape_string($connection, $password);
  7.  
  8. $hashFormat = '$2y$07$';
  9. $salt = 'usesomesillystringforsalt$';
  10. $hashF_salt = $hashFormat . $salt;
  11. $password = crypt($password, $hashF_salt);
  12.  
  13. $query = "INSERT INTO users(username, password) ";
  14. $query .= "VALUES('$username', '$password')";
  15. $result = mysqli_query($connection, $query);
  16. if(!$result) {
  17. die(mysql_error());
  18. } else {
  19. echo "Created";
  20. }
  21. }
  22.  
  23. // create.php
  24. <?php include "functions.php"; ?>
  25. if(isset($_POST['submit'])) {
  26. $username = $_POST['username'];
  27. $password = $_POST['password'];
  28.  
  29. if($username && $password) {
  30. createData();
  31. } else {
  32. echo "Input can not be blank";
  33. }
  34. }
Add Comment
Please, Sign In to add comment