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

ServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 4
lcom 1
cbo 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