Passed
Branch master (249862)
by Adam
07:51
created

ServiceProvider::boot()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.2
1
<?php
2
3
namespace Coyote\Plugins\Password;
4
5
use Illuminate\Auth\Events\Attempting;
6
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
7
use Coyote\User;
8
9
class ServiceProvider extends EventServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        parent::boot();
19
20
        // W starej wersji 4programmers.net hasla byly hashowane przy pomocy sha256 + sol. Jezeli w bazie
21
        // danych jest stary hash, to zmieniamy hasha i zapisujemy do bazy danych
22
        $this->app['events']->listen(Attempting::class, function (Attempting $attempting) {
23
            $user = User::where('name', $attempting->credentials['name'])->first();
24
25
            if ($user && $user->salt
26
                && $user->password === hash('sha256', $user->salt . $attempting->credentials['password'])) {
27
                $user->password = bcrypt($attempting->credentials['password']);
28
                $user->salt = null;
29
                $user->save();
30
            }
31
        });
32
    }
33
}
34