Laravel multiauth md5 and primary key string

currently i have 1 project need to use extend mysql database which has a lot of data and password is md5 encrypted and the MEMBER_ID(primary key) is string like this

5e3bb0bdb70e4f139c132cc32daace0e

the password field name PASSWORD and the primary key name MEMBER_ID

so i set the eloquent model like this


<?php

namespace AppModels;

use Auth;
use IlluminateAuthAuthenticatable;
use IlluminateFoundationAuthAccessAuthorizable;
use IlluminateContractsAuthAuthenticatable as AuthenticatableContract;
use IlluminateContractsAuthAccessAuthorizable as AuthorizableContract;

class Member extends BaseModels implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;

protected $connection = 'mysql_db2';

protected $table = 'tb_member';

protected $primaryKey = 'MEMBER_ID';

protected $fillable = [];

public $incrementing = false;

protected $hidden = ['PASSWORD'];

public function getAuthIdentifier() {
return $this->MEMBER_ID;
}

public function setPASSWORDAttribute($value) {
$this->attributes['PASSWORD'] = static::encryptPassword($value);
}

public function setPassword($password) {dd('set');
$this->PASSWORD = static::encryptPassword($password);
}

public function getAuthPassword() {dd('get');
return $this->PASSWORD;
}

public static function encryptPassword($password) {
return md5($password);
}

public function checkLogin($username, $password) {
if ($this->USERNAME == $username && $this->PASSWORD == static::encryptPassword($password)) {
return true;
} else {
return false;
}
}
}

i search around and found some post mention to add the getAuthPassword() and setPassword() method, but i die dump there it also pass, so i think is deprecated in laravel 5.2?

and here is my controller


<?php

namespace AppHttpControllersAuth;

use AppModelsMember;
use Validator;
use AppHttpControllersController;
use IlluminateFoundationAuthThrottlesLogins;
use IlluminateFoundationAuthAuthenticatesAndRegistersUsers;
use IlluminateHttpRequest;
use Auth;

class MemberController extends Controller {
use AuthenticatesAndRegistersUsers, ThrottlesLogins;

public function login(Request $request) {
$username = $request->get('username');
$password = $request->get('password');

try {
$member = Member::where('USERNAME', '=', $username)->first();
dd(Auth::guard('member')->attempt([
'USERNAME' => $username,
'PASSWORD' => $password
]));
if ($member) {
if ($member->checkLogin($username, $password)) {

Auth::guard('member')->login($member);
if (Auth::guard('member')->check()) {
// dd(Auth::guard('member')->check());
return redirect()->route('frontend.index');
} else {
return redirect()->route('frontend.index')->withErrors();
}
} else {
return 'Incorrect password';
}
} else {
return 'Username not found';
}
$d = new Member();
$d->PASSWORD = 123456;

$credentials = [
'USERNAME' => $username,
'PASSWORD' => $password
];
if (Auth::guard('member')->attempt($credentials)) {
return 'successfully login';
} else {
return 'unable to login';
}
return 'hehe';
// dd($username, $password);
} catch (Exception $e) {
dd('FILE: ' . $e->getfile() . 'LINE: ' . $e->getLine() . '<br />' . $e->getMessage());
}
}
}

the Auth::guard(‘member’)->attempt() always return false

the Auth::guard(‘member’)->login($member) always return null

Auth::guard(‘member’)->check() return true when the page not refresh, but once refresh(or go another route/page) the Auth::guard(‘member’)->check() will then return false

i cannot change the password encrypt method, i cannot add a auto increment field or edit the primary key to the member table because another website maintainer say it might cause his JAVA application error, so any idea without changing any table structure?

from Newest questions tagged laravel-5 – Stack Overflow http://ift.tt/1mxJIyh
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.