I have a folder named API, inside which I have my .php files. The files are new_user.php
(the source file), a file called db_connexion.php
(which opens a PDO connection to my mySQL database) and a Phpass file called PasswordHash.php
.
Following this tutorial that I found googling, I visited this site, downloaded the source file, added PasswordHash.php
into my API folder. Now when I try to include the PasswordHash into my new_user file I need to reference it like this :include '/PasswordHash.php';
, or I get the following error: Class 'PasswordHash' not found
. When I reference it like this though, I get "NetworkError: 500 Internal Server Error - http://localhost/PTC/API/new_user.php"
.
What am I doing wrong (I'm trying to setup password encryptioon before writing it into my database)?
this is what my AngularJS apps register form sends as a POST request:
{"email":"email@example.com","username":"mihamiha","password":"ex4mPl3"}
new_user.php:
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: Authorization, Content-Type');
// pass hashing library
include '/PasswordHash.php';
// database connection file
include '/db_connexion.php';
$data = file_get_contents("php://input");
$data = json_decode($data, true);
// check if data is there
if (isset($data['email']) && isset($data['username']) && isset($data['password'])) {
// if email is properly formatted
if (preg_match('/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/', $data['email'])) {
// remove whitespace from beginning
$email = trim($data['email']);
}
// strips html, php tags, removes whitespace from beginning/end
$username = strip_tags(trim($data['username']));
$pass = $data['password'];
// hash object
$hash_obj = new PasswordHash( 8, false );
// hash pass
$hash = $hash_obj->HashPassword($pass);
}
else {
echo 'data missing!';
}
die();