0

I have a simple login and I have been unable to find the error for 2 days now. I have the required login and password in the database, but no matter what I enter in the login, I am thrown out and it says that the login or password is incorrect. Im using sqllite laravel-10 php AuthController

class AuthController extends Controller
{
    public function showLoginForm()
    {
        return view("auth.login");
    }
    public function login(Request $request)
    {
        $data = $request->validate([
            "email" => ["required", "email", "string"],
            "password" => ["required"]
        ]);

        if(auth("web")->attempt($data)) {
            return redirect(route("home"));
        }
        return redirect(route("login"))->withErrors(["email" => "wrong data"]);
    }


    public function logout()
    {
        auth("web")->logout();

        return redirect(route("login"));
    }
}

config/auth.php

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
    ],

web.php

Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login_process', [AuthController::class, 'login'])->name('login_process');

App/Models/User.php

class User extends Authenticatable
{
    use HasFactory;
    protected $fillable = [
        'email',
        'name',
        'role',
        'status',
        'password',
    ];
}

When I enter the correct data from the database, it just gives an error that the data is incorrect. i alse add admin user to the db

       DB::table('users')->insert([
        'email' => '[email protected]',
        'name' => 'admin',
        'role' => 'admin',
        'password' => 'admin',
    ]);

i tried to find answers and use different auth methods but nothig works

9
  • You have a syntax error here, unless this happened while pasting ... ["email" => wrong data"] Commented Mar 18, 2024 at 13:52
  • error when pasting. Fixed Commented Mar 18, 2024 at 13:56
  • Ensure that the sqlite file is not open by another application. What are you using to view it? Commented Mar 18, 2024 at 13:58
  • Database tool in phpstorm Commented Mar 18, 2024 at 13:59
  • This statement if(auth("web")->attempt($data)) { appears to always return false. Begin your debugging here. By "debugging" you'll have to log the state. You can do this by outputting whichever state to an external file. Commented Mar 18, 2024 at 14:00

1 Answer 1

-1

I created a user with

DB::table('users')->insert([
    'email' => '[email protected]',
    'name' => 'admin',
    'role' => 'admin',
    'password' => 'admin',
]);

but it didn't work. But then I changed password to

'password' => bcrypt('admin'),

and this worked

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.