簡體   English   中英

Laravel 5.7 身份驗證無法成功

[英]Laravel 5.7 auth can't get success

我嘗試制作 auth API,我注冊成功。 比登錄不能成功。 請幫助我,謝謝。

public function login(Request $request)
{
    try
    {
        if (!$request->has('Account') 
        || !$request->has('Password'))
        {
         throw new Exception('Parameter missing');
        }

         $checkUser = DB::table('Users')->where('Account',$request->Account)->first();
        if(empty($checkUser))
        {
            throw new Exception('No Data');
        }
        $data = ([
            'Account' => $request->Account,
            'Password' => $request->Password,
        ]);  

        if(!Auth::attempt($data))
        throw new Exception('Verification error'); 

這個數據庫信息。

在此處輸入圖片說明

嘗試以下注冊需要在保存到數據庫之前散列密碼:

User::create([
    'Account' => $request->Account,
    'CreateDateTime' => date('Y-m-d'),
    'UpdatedDateTime' => date('Y-m-d'),
    'Password' => Hash::make($request->Password),
]);  

嘗試這種方式它可能會有所幫助,並且還可以使用 evn ry 驗證器:如果不確定密碼,則首先進行調試

   $table->string('password', 60)->nullable();
    ----------------------------------------------------
   return Validator::make($data, [
        'email' => 'required|email',
        'password' => 'required',
    ]);
    -----------------------------------------------
   $user_data=User::where('username','=',$request->username)->first();
   $userScope=$user_data->scope;

   Input::merge([
        'client_id' => env('CLIENT_ID'),
        'client_secret' => env('CLIENT_SECRET'),
        'scope' => 'admin'
    ]);

    $credentials = $request->only(['grant_type', 'username', 'password','scope']);


    $validationRules = $this->getLoginValidationRules();

    $credentials["client_id"] = env('CLIENT_ID');
    $credentials["client_secret"] = env('CLIENT_SECRET');


    $this->validateOrFail($credentials, $validationRules);

    try {
        if (!$accessToken = Authorizer::issueAccessToken()) {
            return $this->response->errorUnauthorized();
        }
    } catch (\League\OAuth2\Server\Exception\OAuthException $e) {
        throw $e;
        return $this->response->error('could_not_create_token', 500);
    }

    $accessToken["groups"][] = $userScope;

    return response()->json(compact('accessToken'));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM