PHP加密登录凭据访问API
我正在尝试调用Harvest API。但是,为了做到这一点,用户名和密码必须放在PHP文件中。现在,我担心安全问题,我不想直接将我的登录凭据放入文件中。我读过一些散列机制,比如SHA1、md5。这适用于我的情况吗?因为我现在看到的大多数示例都是基于验证登录凭据的。在这里,我需要一种方法来隐藏我的登录凭据,这样它就不会公开。请建议一种解决方法PHP加密登录凭据访问API,php,api,hash,login,Php,Api,Hash,Login,我正在尝试调用Harvest API。但是,为了做到这一点,用户名和密码必须放在PHP文件中。现在,我担心安全问题,我不想直接将我的登录凭据放入文件中。我读过一些散列机制,比如SHA1、md5。这适用于我的情况吗?因为我现在看到的大多数示例都是基于验证登录凭据的。在这里,我需要一种方法来隐藏我的登录凭据,这样它就不会公开。请建议一种解决方法 $user= //Actual username; $password= //Actual Password $harvest_user = $user;
$user= //Actual username;
$password= //Actual Password
$harvest_user = $user; // Harvest username, usually an email address
$harvest_pass = $password; // Harvest password
$harvest_account = $account;
require_once 'HarvestAPI.php';
spl_autoload_register(array('HarvestAPI', 'autoload') );
$harvestAPI = new HarvestAPI();
$harvestAPI->setUser($harvest_user);
$harvestAPI->setPassword($harvest_pass);
$harvestAPI->setAccount($harvest_account);
$result = $harvestAPI->getUsers();
// If Harvest returns successful
if ($result->code == 200) {
$people = $result->data;
}
else{
echo "Not Successful";
}
?>
您可以使用md5()
方法
只需在注册后对密码进行加密,并将其存储在数据库中或存储登录信息的其他位置
在登录时,只需加密键入的密码,并检查密码是否与数据库中的密码相同
没有人可以从数据库中获取密码,因为md5()
方法不可用
可逆的
像这样加密:$pw2store=md5($password)代码>
或者用加密密码替换密码:$password=md5($password)代码>
希望我能帮忙
if (!defined('access')): die('no access for you');
class HarvestAPI
{
private $username;
private $...;
public function __construct($u,$...)
{
$this->username = $u;
}
public function start()
{
require_once 'HarvestAPI.php';
spl_autoload_register(array('HarvestAPI', 'autoload') );
$harvestAPI = new HarvestAPI();
$harvestAPI->setUser($this->username);
$harvestAPI->setPassword($....);
$harvestAPI->setAccount($....);
return $harvestAPI->getUsers();
}
}
用法(在另一个文件中):
define('access',0);
require_once 'thatfileabove.php';
$result = (new HarvestAPI('username','ect..'))->start();
($result->code == 200)? $people = $result->data : "Not Successful";
除非有人查看您的代码,否则他们现在不可能看到您的凭据。听说过彩虹表吗?您真的不应该使用PHP来处理密码安全问题。如果您使用的PHP版本低于5.5,可以使用密码\u hash()
。这是我的否决票。我这么做是因为推荐不好。“收到”山姆@杰布兰查德我看到你的耳朵在那儿了,山姆@JAYBLANCHARD sha1和MD5不再被认为是安全的密码哈希/存储。请使用PHP来处理密码安全性。如果您使用的PHP版本低于5.5,则可以使用密码\u hash()
。