Passed
Push — master ( 7a263d...e0b6af )
by Ferry
05:04
created

AuthSuspend::clearSuspendAttempt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 8/14/2019
6
 * Time: 8:44 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\controllers;
10
11
use Illuminate\Support\Facades\Cache;
12
13
trait AuthSuspend
14
{
15
16
    private function clearSuspendAttempt() {
17
        $key = md5(request()->ip().request()->userAgent());
18
        Cache::forget("loginFailed".$key);
19
    }
20
21
    private function incrementFailedLogin()
22
    {
23
        $key = md5(request()->ip().request()->userAgent());
24
        Cache::increment("loginFailed".$key, 1);
25
    }
26
27
    private function isSuspendedLogin()
28
    {
29
        $key = md5(request()->ip().request()->userAgent());
30
31
        if(Cache::has("loginSuspended".$key)) {
32
            return true;
33
        }
34
35
        if(getSetting("AUTO_SUSPEND_LOGIN") && Cache::get("loginFailed".$key) >= getSetting("AUTO_SUSPEND_LOGIN")) {
36
            Cache::put("loginSuspended".$key, true, 30);
37
            $this->clearSuspendAttempt();
38
            return true;
39
        }
40
41
        return false;
42
    }
43
44
}