Did you changed 'password' column name in database?
can you paste the code involved with getting the data and passing it to Auth::attempt
i didnt change 'password' coulmn name in data base!!!
doLogin Function that authenticate users is :
public function doLogin() {
$rules = array(
'email' => 'required|email',
'password' => 'required|alphaNum'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
// create our user data for the authentication
$userdata = array(
'password' => Input::get('password'),
'email' => Input::get('email')
);
// attempt to do the login
if (Auth::attempt($userdata,true)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
//return Redirect::to('Home');
echo 'SUCCESS!';
echo Auth::user()->uname;
} else {
// validation not successful, send back to form
echo "string";
}
}
}
First off: hash your passwords! Always a good idea. Second: allow for passwords to be any character, not just alphaNum.
So it's not the validator that fails, but the login attempt?
I suspect your auth.php
config file specifies the right model and the model has the right table name?
Could you view the laracast video on this, it would really clear up some stuff.
You need to have the passwords hashed in the db to use Auth::attempt
. It compares the hashed value.
i hashed the password ,but my problem dont solve,
is it true my validation code after my password saved hashe? $userdata = array(
'password' => Input::get('password'),
'email' => Input::get('email')
);
if (Auth::attempt($userdata)) {
echo 'SUCCESS!';
} else {
echo "Fail";
yes, i used $password = Hash::make(Input::get("password","")); then i saved it :$user=new User(); $user->password=$password;
What is the size/length of your password field in your database, it needs to be at least 60 characters to be big enough to store the hashed password. If it's too short, the hash will be incomplete and auth::attempt will never succeed.
its 100 character , when i hashed a password and saved in db,is not require to rehash this password and check with the users password in the login form???!!!
No, only hash the password when saving it to the database, don't hash it again when you try to log them in.
thanks my problem solve! after i hashed password and extend character of password field , my problem solved but i had a brief mistake in my code,
saghafi said:
thanks my problem solve! after i hashed password and extend character of password field , my problem solved but i had a brief mistake in my code,
Also, do not forget about remember_token.
I am getting this error in lumen 5.6
Method Illuminate\Auth\RequestGuard::attempt does not exist.
My controller class
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
use App\User;
use Auth;
Use Validator;
class UserController extends Controller {
//use AuthenticatesUsers;
public function login(Request $request)
{
if(Auth::attempt(['email' => request('email'), 'password' => request('password'), 'users_status_id' => '1']))
{
// return json_encode($user);
$request->request->add([
'grant_type' => 'password',
'client_id' => config('global.API_CLIENT_ID'),
'client_secret' => config('global.API_CLIENT_SECRET'),
'scope' => '*'
]);
// forward the request to the oauth token request endpoint
$tokenRequest = Request::create('/oauth/token','post');
return $passport_response_arr = Route::dispatch($tokenRequest);
}
else{
return response()->json(['error' => 'Unauthorised']);
}
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community