Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vidhyaprakash85's avatar

Laravel custom auth not working date of birth as password and username as registerno

I have a custom auth for my application.

<?php

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

        'student' => [
            'driver' => 'eloquent',
            'model' => App\Models\Student::class,
        ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],
    'password_timeout' => 10800,
];

This is LoginController i am checking manually

<?php

namespace App\Http\Controllers\Auth\Student;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = RouteServiceProvider::HOME;


    public function login_show()
    {
        return view('student.login');
    }

    public function student_login(Request $request)
    {
        if (Auth::guard('student')->attempt(['registerno' => '20MBA002', 'password' => '1999-08-25'])) {
            return "LOGIN SUCCESS";
        } else {
            return "Login Failed";
        }
    }
    public function logout(Request $request)
    {
        Auth::guard('student')->logout();
        return redirect(route('student.login'));
    }
}

In Student Model i have

<?php

namespace App\Models;

use App\Models\InternalMark;
use Illuminate\Support\Carbon;
use App\Models\MasterTables\Batch;
use Spatie\Activitylog\LogOptions;
use App\Models\MasterTables\Course;
use App\Models\MasterTables\Gender;
use App\Models\MasterTables\Meduim;
use App\Models\MasterTables\Section;
use App\Models\MasterTables\Community;
use App\Models\MasterTables\Programme;
use App\Models\MasterTables\Regulation;
use Illuminate\Database\Eloquent\Model;
use App\Models\MasterTables\StudentStatus;
use Spatie\Activitylog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\ExamPreProcess\ExamApplication;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class Student extends Authenticatable
{
    use SoftDeletes, LogsActivity, HasRoles;
    protected $guard = 'student';


    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'registerno',
        'rollno',
        'admission_no',
        'name',
        'regulation_id',
        'course_id',
        'programme_id',
        'batch_id',
        'dob',
        'gender_id',
        'community_id',
        'fathername',
        'father_phoneno',
        'mothername',
        'mother_phoneno',
        'c1_address',
        'c2_address',
        'c3_address',
        'c_pincode',
        'p1_address',
        'p2_address',
        'p3_address',
        'p_pincode',
        'phoneno',
        'email',
        'photo',
        'section_id',
        'medium_id',
        'studentstatus_id',
        'voterid',
        'aadharno',
        'passportno'
    ];
protected function dob(): Attribute
    {
        return new Attribute(
            get: fn ($value) =>  Carbon::parse($value)->format('d-m-Y'),
            set: fn ($value) =>  Carbon::parse($value)->format('Y-m-d'),
        );
    }
    public function getAuthPassword()
    {
        return $this->dob;
    }
}

i am trying very hard and i dont know where i did the mistake. Please help me.

0 likes
4 replies
tisuchi's avatar

@vidhyaprakash85 I think it's because of you are trying to use hardcoded registerno and password. You need to use what the user fill-up in the form.

 if (Auth::guard('student')->attempt(['registerno' => '20MBA002', 'password' => '1999-08-25'])) {
vidhyaprakash85's avatar

@tisuchi no sir I am testing whether it is working or not. Then I will update with form data. Please help me

jlrdw's avatar

I would suggest not using birthday as a password. Use a proper bcrypted password.

Please or to participate in this conversation.