【发布时间】:2016-09-01 04:12:15
【问题描述】:
我正在 laravel 中制作 api。我正在使用已经构建并处于活动状态的数据库。该系统使用带有盐值的 md5。 我想对该系统进行身份验证。我该怎么办? 我的源代码:
public function authenticate(Request $request)
{
$email = $request->input('email');
$password = md5('testpassword' . 'saltvaluehere');
try {
//
// attempt to verify the credentials and create a token for the user
if (!$token = JWTAuth::attempt([
'email' => $email,
'pass' => $password
])
) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
在核心 php 中,这些身份验证通过以下方式完成:
$getpass = $mydb->CleanString($_POST['password']);
$getusername = $mydb->CleanString($_POST['username']);
$dbpass = $mydb->md5_decrypt($mydb->getValue("pass","tbl_admin","username = '".$getusername."'"), SECRETPASSWORD);
if($dbpass == $getpass){
return 'success full login';
}
上面的代码没有给出相同的哈希值,所以我无法在系统中进行身份验证。
已编辑:
我得到了与数据库匹配的密码,但没有生成令牌。
这是我的代码:
public function authenticate(Request $request)
{
$email = $request->input('email');
$password = $request->input('password');
$password = md5($password);
try {
//
// attempt to verify the credentials and create a token for the user
if (!$token = JWTAuth::attempt([
'email' => $email,
'password' => $password
])
){
//return response()->json(compact('token'));
return response()->json(['error' => 'invalid_credentials','_data'=>[$password,$email]], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
谁能告诉我为什么没有生成令牌以及为什么它说无效的凭据。因为它显示了加密形式的数据库的密码和电子邮件。
【问题讨论】:
标签: api laravel authentication encryption login