私はlaravelでapiを作っています。私はすでに構築されており、ライブであるデータベースを使用しています。そのシステムはmd5をsalt値で使用します。 私はそのシステムの認証をしたいと思います。どうすればいいのですか? 私のソースコード:コアPHPでlaravelの認証
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'));
}
これらの認証はによって行われます。コードの上
$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';
}
はハッシュの同じ値を与えるdoesnotので、私はシステムに認証することができるというわけではありません。
編集:私はデータベースに合わせたパスワードを持っているが、トークンが生成されていないbieng
。ここ
は私のコードです:
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'));
}
誰が私にトークン生成されていないと、なぜそれが無効credintialsを言っている理由を伝えることができます。それは暗号化された形式のデータベースのパスワードと電子メールを示しています。