简体   繁体   English

当我通过 API 从 Laravel 的数据库中获取用户数据时出现错误

[英]i am getting error when i am fetching user data from database in laravel through API

Hello Guys nowadays am working on laravel api everything is perfect just one issue am facing that is when i write wrong username and password so i am able to get user data but when i enter correct user information so i am getting exception that is invalid credentials.大家好,现在正在研究 laravel api,一切都很完美,只是我面临的一个问题是,当我写错了用户名和密码时,我能够获取用户数据,但是当我输入正确的用户信息时,我收到了无效凭据的异常。 please help me请帮我

here is my model code这是我的模型代码

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class email extends Model
{
    protected $table = 'users';
}

& Here is my Controller Code &这是我的控制器代码

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\email;

class EmailController extends Controller
{
   public function databyemail(Request $request){   
       $data = email::where('email', $request->email)->first();  
       if($data->password === bcrypt($request->password)) 
       {
           return response()->json($data);
       } 
       else
       {      
           return response()->json(['error' => 'Incorrect credentials!']);  
           } 
           }

} 

Can you try Hash::check method for matching password.你能试试Hash::check方法来匹配密码吗?

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use App\email;

class EmailController extends Controller
{
   public function databyemail(Request $request){   
        $data = email::where('email', $request->email)->first(); 


        if( Hash::check( $request->password, $data->password ) ) {
            return response()->json($data);
        }else{
            return response()->json(['error' => 'Incorrect credentials!']);  
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使我在 laravel api 中获取不同的数据,也从数据库中获取错误的数据 - Getting wrong data from database even if I am fetching something different in laravel api 从数据库获取时,我在CodeIgniter中收到“未定义的变量”错误 - I am getting an “Undefined variable” error in CodeIgniter when fetching from database 为什么我在尝试查找特定用户时从 laravel 的数据库中获取 null 值? - why am i getting null value from my database in laravel when trying to find specific user? 在核心php中获取索引错误。我正在使用ajax和jquery从数据库中获取 - getting index error in core php.. i am fetching from database using ajax and jquery 我是PHP + MySql的新手,并尝试编写一个简单的脚本从数据库中删除用户,但是我没有摆脱错误 - I am new to PHP+MySql,and trying to write a simple script that will delete a user from the database,,but i am not getting rid of a error 我试图为我的数据库播种时出错 - I am getting an error when i tried to seed my database 为什么我从 api 和 api 资源管理器收到 500 错误 - Why am I getting a 500 error from api and api explorer 通过PHP从MySQL获取数据-我做对了吗? - Getting data from MySQL through PHP - am I doing it right? 我在Laravel中遇到异常的url错误 - I am getting an unusual url error in Laravel 我收到 Laravel Mysql 连接错误 - I am getting Laravel Mysql Connection Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM