Ich habe ein seltsames Problem mit Laravel 5, Postgres und der Hash-Fassade. Ich habe den folgenden Testcode:Laravel Hash :: make() und Hash :: check() funktioniert nicht mit Postgres
public static function addNewPartner($args){
$user = new User;
$user->username = $args['username'];
$user->email = $args['email'];
// Here starts the issue
$password = Hash::make($args['password']);
$user->password = $password;
$user->remote_key = str_random(16);
if(!$user->save()){
return false;
}
$role = Role::where('name','=','partner')->first();
$user->attachRole($role);
Log::info("User::addNewPartner. User:" . json_encode($user));
// At this point the password is hashed and saved into DB, I can
// see the record saved.
// I compare the saved password with the input and it fails.
if(Hash::check($args['password'], $user->password)){
Log::info('DB hash' . " " . $password);
} else {
Log::info('DB no hash' . " " . $password);
}
// I compare the password as it was generated with the input and
// it passes.
if(Hash::check($args['password'], $password)){
Log::info('LOCAL hash' . " " . $password);
} else {
Log::info('LOCAL no hash' . " " . $password);
}
return $user;
}
Die Protokollausgabe ist:
[2016.04.28 00.04.46] local.INFO: Usercontroller :: postAddnewpartner. Input: { "Token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIsImlzcyI6Imh0dHA6XC9cL3Vici5sb2NhbDo4MDAwXC9hcGlcL3VzZXJcL2xvZ2luIiwiaWF0IjoxNDYxODYyNDYwLCJleHAiOjE0NjE4NjYwNjAsIm5iZiI6MTQ2MTg2MjQ2MCwianRpIjoiZmU0MTgzMTAwMzQyMjU3Mjg2MGJmOWJhN2FmOWIyMDMifQ.iUZzepZshdn7snUGOzTt3AEAyfRKNGPrCJpk5FxJtxw", "Fullname": "usuario1", "E-Mail": "[email protected]", "Passwort": "1234", "username": "usuario1" }
[2016-04-28 12:04:46] local.INFO: Benutzer :: addNewPartner. Benutzer: {"username": "usuario1", "email": "[email protected]", "remote_key": "jhDpJgolw4bTdsZj", "aktualisiert_at": "2016-04-28 12:04:46", "created_at ":" 2016-04-28 12:04:46 "," id ": 6}
[2016-04-28 12:04:46] local.INFO: DB kein Hash $ 2y $ 10 $ PU24f. AkNguifnh1AkKSJuVu7I4idWGUz8SA2L/37sRsI6JaVkQZC
[2016.04.28 00.04.46] local.INFO: LOCAL Hash $ 2j $ 10 $ PU24f.AkNguifnh1AkKSJuVu7I4idWGUz8SA2L/37sRsI6JaVkQZC
Aus irgendeinem Grund die Hash :: check() funktioniert nicht wenn der Datensatz aus der Datenbank abgerufen wird.
Merkwürdiger des Test Benutzer während der Aussaat Prozess Arbeit erstellt:
class UserTableSeeder extends Seeder {
public function run() {
$users = array(
array(
'username' => 'admin',
'email' => '[email protected]',
'password' => Hash::make('1234'),
'parent_id'=>null,
'created_at' => new DateTime,
'updated_at' => new DateTime,
),
Meine Benutzermigration ist:
public function up() {
Schema::create('users', function(Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable();
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password', 60);
$table->string('remote_key')->default(str_random(16));
$table->rememberToken();
$table->timestamps();
});
}
Wissen Sie, warum die Hash versagt? Vielen Dank.