我有一个名为API的文件夹,里面有我的.php文件。这些文件是new_user.php
(源文件),一个名为db_connexion.php
的文件(用于打开与mySQL数据库的PDO连接)和一个名为PasswordHash.php
的Phpass文件。
我发现谷歌搜索this tutorial后,我访问了this site,下载了源文件,将PasswordHash.php
添加到了我的API文件夹中。现在,当我尝试将PasswordHash包含到我的new_user文件中时,我需要像这样引用它:include '/PasswordHash.php';
,或者我收到以下错误:Class 'PasswordHash' not found
。当我像这样引用它时,我得到"NetworkError: 500 Internal Server Error - http://localhost/PTC/API/new_user.php"
。
我做错了什么(我想在将密码加密到我的数据库之前设置密码加密)?
这是我的AngularJS应用程序注册表单作为POST请求发送的内容:
{"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();