Completed
Push — master ( bbdfbe...3990e5 )
by
unknown
01:23
created
tests/Controller/SettingsControllerTest.php 2 patches
Unused Use Statements   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@
 block discarded – undo
20 20
  */
21 21
 namespace OCA\Security\Tests\Controller;
22 22
 
23
-use OCA\Security\Controller\SettingsController;
24
-use OCA\Security\SecurityConfig;
25
-use OCP\IRequest;
23
+use OCA\Security\Controller\SettingsController;
24
+use OCA\Security\SecurityConfig;
25
+use OCP\IRequest;
26 26
 use Test\TestCase;
27 27
 
28 28
 class SettingsControllerTest extends TestCase {
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -26,32 +26,32 @@
 block discarded – undo
26 26
 use Test\TestCase;
27 27
 
28 28
 class SettingsControllerTest extends TestCase {
29
-	/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
30
-	private $request;
31
-	/** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */
32
-	private $config;
33
-	/** @var SettingsController */
34
-	private $controller;
35
-	protected function setUp() {
36
-		parent::setUp();
37
-		$this->request = $this->getMockBuilder(IRequest::class)->getMock();
38
-		$this->config = $this->getMockBuilder(SecurityConfig::class)
39
-			->disableOriginalConstructor()
40
-			->getMock();
41
-		$this->controller = new SettingsController('security', $this->request, $this->config);
42
-	}
43
-	public function testState() {
44
-		$expected = [
45
-			'bruteForceProtectionState' => true,
46
-			'minPassLength' => 8,
47
-			'enforceUpperLowerState' => true,
48
-			'enforceNumericalCharactersState' => true,
49
-			'enforceSpecialCharactersState' => true
50
-		];
51
-		$this->config->expects($this->exactly(1))
52
-			->method('getAllSecurityConfigs')
53
-			->willReturn($expected);
29
+    /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
30
+    private $request;
31
+    /** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */
32
+    private $config;
33
+    /** @var SettingsController */
34
+    private $controller;
35
+    protected function setUp() {
36
+        parent::setUp();
37
+        $this->request = $this->getMockBuilder(IRequest::class)->getMock();
38
+        $this->config = $this->getMockBuilder(SecurityConfig::class)
39
+            ->disableOriginalConstructor()
40
+            ->getMock();
41
+        $this->controller = new SettingsController('security', $this->request, $this->config);
42
+    }
43
+    public function testState() {
44
+        $expected = [
45
+            'bruteForceProtectionState' => true,
46
+            'minPassLength' => 8,
47
+            'enforceUpperLowerState' => true,
48
+            'enforceNumericalCharactersState' => true,
49
+            'enforceSpecialCharactersState' => true
50
+        ];
51
+        $this->config->expects($this->exactly(1))
52
+            ->method('getAllSecurityConfigs')
53
+            ->willReturn($expected);
54 54
 
55
-		$this->assertEquals($expected, $this->controller->state());
56
-	}
55
+        $this->assertEquals($expected, $this->controller->state());
56
+    }
57 57
 }
58 58
\ No newline at end of file
Please login to merge, or discard this patch.
tests/PasswordValidatorTest.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
 	}
44 44
 
45 45
 	/**
46
-	 * @param array $mockedMethods
46
+	 * @param string[] $mockedMethods
47 47
 	 * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject
48 48
 	 */
49 49
 	private function getMockInstance($mockedMethods = []) {
Please login to merge, or discard this patch.
Unused Use Statements   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@
 block discarded – undo
19 19
  *
20 20
  */
21 21
 namespace OCA\Password_Policy\Tests;
22
-use OC\HintException;
23
-use OCA\Security\SecurityConfig;
24
-use OCA\Security\PasswordValidator;
25
-use OCP\IL10N;
22
+use OC\HintException;
23
+use OCA\Security\SecurityConfig;
24
+use OCA\Security\PasswordValidator;
25
+use OCP\IL10N;
26 26
 use Test\TestCase;
27 27
 class PasswordValidatorTest extends TestCase {
28 28
 
Please login to merge, or discard this patch.
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -26,155 +26,155 @@
 block discarded – undo
26 26
 use Test\TestCase;
27 27
 class PasswordValidatorTest extends TestCase {
28 28
 
29
-	/** @var  SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */
30
-	private $config;
29
+    /** @var  SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */
30
+    private $config;
31 31
 
32
-	/** @var  IL10N|\PHPUnit_Framework_MockObject_MockObject */
33
-	private $l10n;
32
+    /** @var  IL10N|\PHPUnit_Framework_MockObject_MockObject */
33
+    private $l10n;
34 34
 
35
-	/** @var  PasswordValidator */
36
-	private $passValidator;
35
+    /** @var  PasswordValidator */
36
+    private $passValidator;
37 37
 
38
-	public function setUp() {
39
-		parent::setUp();
40
-		$this->l10n = $this->createMock(IL10N::class);
41
-		$this->config = $this->createMock(SecurityConfig::class);
42
-		$this->passValidator = new PasswordValidator($this->config, $this->l10n);
43
-	}
38
+    public function setUp() {
39
+        parent::setUp();
40
+        $this->l10n = $this->createMock(IL10N::class);
41
+        $this->config = $this->createMock(SecurityConfig::class);
42
+        $this->passValidator = new PasswordValidator($this->config, $this->l10n);
43
+    }
44 44
 
45
-	/**
46
-	 * @param array $mockedMethods
47
-	 * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject
48
-	 */
49
-	private function getMockInstance($mockedMethods = []) {
50
-		$passwordValidator = $this->getMockBuilder('OCA\Security\PasswordValidator')
51
-			->setConstructorArgs([$this->config, $this->l10n])
52
-			->setMethods($mockedMethods)->getMock();
53
-		return $passwordValidator;
54
-	}
45
+    /**
46
+     * @param array $mockedMethods
47
+     * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject
48
+     */
49
+    private function getMockInstance($mockedMethods = []) {
50
+        $passwordValidator = $this->getMockBuilder('OCA\Security\PasswordValidator')
51
+            ->setConstructorArgs([$this->config, $this->l10n])
52
+            ->setMethods($mockedMethods)->getMock();
53
+        return $passwordValidator;
54
+    }
55 55
 
56
-	public function testCheckPasswordLength() {
57
-		$this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
58
-		$this->passValidator->checkPasswordLength('password');
59
-	}
60
-	/**
61
-	 * @expectedException \OC\HintException
62
-	 */
63
-	public function testCheckPasswordLengthFail() {
64
-		$this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
65
-		$this->passValidator->checkPasswordLength('123');
66
-	}
67
-	/**
68
-	 * @dataProvider dataTestCheckUpperLowerCase
69
-	 *
70
-	 * @param string $password
71
-	 * @param bool $enforceUpperLowerCase
72
-	 */
73
-	public function testCheckUpperLowerCase($password, $enforceUpperLowerCase) {
74
-		$this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')
75
-			->willReturn($enforceUpperLowerCase);
76
-		$this->passValidator->checkUpperLowerCase($password);
77
-	}
78
-	public function dataTestCheckUpperLowerCase() {
79
-		return [
80
-			['testPass', true],
81
-			['Testpass', true],
82
-			['testpass', false],
83
-			['TESTPASS', false],
84
-		];
85
-	}
86
-	/**
87
-	 * @dataProvider dataTestCheckUpperLowerCaseFail
88
-	 * @param string $password
89
-	 * @expectedException \OC\HintException
90
-	 */
91
-	public function testCheckUpperLowerCaseFail($password) {
92
-		$this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')->willReturn(true);
93
-		$this->passValidator->checkUpperLowerCase($password);
94
-	}
95
-	public function dataTestCheckUpperLowerCaseFail() {
96
-		return [
97
-			['TESTPASS'], ['testpass']
98
-		];
99
-	}
100
-	/**
101
-	 * @dataProvider dataTestCheckNumericCharacters
102
-	 *
103
-	 * @param string $password
104
-	 * @param bool $enforceNumericCharacters
105
-	 */
106
-	public function testCheckNumericCharacters($password, $enforceNumericCharacters) {
107
-		$this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn($enforceNumericCharacters);
108
-		$this->passValidator->checkNumericCharacters($password);
109
-	}
110
-	public function dataTestCheckNumericCharacters() {
111
-		return [
112
-			['testPass1', true],
113
-			['testpass', false]
114
-		];
115
-	}
116
-	/**
117
-	 * @dataProvider dataTestCheckNumericCharactersFail
118
-	 * @param string $password
119
-	 * @expectedException \OC\HintException
120
-	 */
121
-	public function testCheckNumericCharactersFail($password) {
122
-		$this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn(true);
123
-		$this->passValidator->checkNumericCharacters($password);
124
-	}
125
-	public function dataTestCheckNumericCharactersFail() {
126
-		return [
127
-			['testpass'],
128
-			['TestPass%'],
129
-			['TEST*PASS']
130
-		];
131
-	}
132
-	/**
133
-	 * @dataProvider dataTestCheckSpecialCharacters
134
-	 *
135
-	 * @param string $password
136
-	 * @param bool $enforceSpecialCharacters
137
-	 */
138
-	public function testCheckSpecialCharacters($password, $enforceSpecialCharacters) {
139
-		$this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn($enforceSpecialCharacters);
140
-		$this->passValidator->checkSpecialCharacters($password);
141
-	}
142
-	public function dataTestCheckSpecialCharacters() {
143
-		return [
144
-			['testPass%', true],
145
-			['testpass', false]
146
-		];
147
-	}
148
-	/**
149
-	 * @dataProvider dataTestCheckSpecialCharactersFail
150
-	 * @param string $password
151
-	 * @expectedException \OC\HintException
152
-	 */
153
-	public function testCheckSpecialCharactersFail($password) {
154
-		$this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn(true);
155
-		$this->passValidator->checkSpecialCharacters($password);
156
-	}
157
-	public function dataTestCheckSpecialCharactersFail() {
158
-		return [
159
-			['testpass'],
160
-			['TestPass1'],
161
-			['TEST2PASS']
162
-		];
163
-	}
164
-	public function testValidate() {
165
-		$password = 'password';
166
-		$instance = $this->getMockInstance(
167
-			[
168
-				'checkPasswordLength',
169
-				'checkUpperLowerCase',
170
-				'checkNumericCharacters',
171
-				'checkSpecialCharacters',
172
-			]
173
-		);
174
-		$instance->expects($this->once())->method('checkPasswordLength')->with($password);
175
-		$instance->expects($this->once())->method('checkUpperLowerCase')->with($password);
176
-		$instance->expects($this->once())->method('checkNumericCharacters')->with($password);
177
-		$instance->expects($this->once())->method('checkSpecialCharacters')->with($password);
178
-		$instance->validate($password);
179
-	}
56
+    public function testCheckPasswordLength() {
57
+        $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
58
+        $this->passValidator->checkPasswordLength('password');
59
+    }
60
+    /**
61
+     * @expectedException \OC\HintException
62
+     */
63
+    public function testCheckPasswordLengthFail() {
64
+        $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
65
+        $this->passValidator->checkPasswordLength('123');
66
+    }
67
+    /**
68
+     * @dataProvider dataTestCheckUpperLowerCase
69
+     *
70
+     * @param string $password
71
+     * @param bool $enforceUpperLowerCase
72
+     */
73
+    public function testCheckUpperLowerCase($password, $enforceUpperLowerCase) {
74
+        $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')
75
+            ->willReturn($enforceUpperLowerCase);
76
+        $this->passValidator->checkUpperLowerCase($password);
77
+    }
78
+    public function dataTestCheckUpperLowerCase() {
79
+        return [
80
+            ['testPass', true],
81
+            ['Testpass', true],
82
+            ['testpass', false],
83
+            ['TESTPASS', false],
84
+        ];
85
+    }
86
+    /**
87
+     * @dataProvider dataTestCheckUpperLowerCaseFail
88
+     * @param string $password
89
+     * @expectedException \OC\HintException
90
+     */
91
+    public function testCheckUpperLowerCaseFail($password) {
92
+        $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')->willReturn(true);
93
+        $this->passValidator->checkUpperLowerCase($password);
94
+    }
95
+    public function dataTestCheckUpperLowerCaseFail() {
96
+        return [
97
+            ['TESTPASS'], ['testpass']
98
+        ];
99
+    }
100
+    /**
101
+     * @dataProvider dataTestCheckNumericCharacters
102
+     *
103
+     * @param string $password
104
+     * @param bool $enforceNumericCharacters
105
+     */
106
+    public function testCheckNumericCharacters($password, $enforceNumericCharacters) {
107
+        $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn($enforceNumericCharacters);
108
+        $this->passValidator->checkNumericCharacters($password);
109
+    }
110
+    public function dataTestCheckNumericCharacters() {
111
+        return [
112
+            ['testPass1', true],
113
+            ['testpass', false]
114
+        ];
115
+    }
116
+    /**
117
+     * @dataProvider dataTestCheckNumericCharactersFail
118
+     * @param string $password
119
+     * @expectedException \OC\HintException
120
+     */
121
+    public function testCheckNumericCharactersFail($password) {
122
+        $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn(true);
123
+        $this->passValidator->checkNumericCharacters($password);
124
+    }
125
+    public function dataTestCheckNumericCharactersFail() {
126
+        return [
127
+            ['testpass'],
128
+            ['TestPass%'],
129
+            ['TEST*PASS']
130
+        ];
131
+    }
132
+    /**
133
+     * @dataProvider dataTestCheckSpecialCharacters
134
+     *
135
+     * @param string $password
136
+     * @param bool $enforceSpecialCharacters
137
+     */
138
+    public function testCheckSpecialCharacters($password, $enforceSpecialCharacters) {
139
+        $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn($enforceSpecialCharacters);
140
+        $this->passValidator->checkSpecialCharacters($password);
141
+    }
142
+    public function dataTestCheckSpecialCharacters() {
143
+        return [
144
+            ['testPass%', true],
145
+            ['testpass', false]
146
+        ];
147
+    }
148
+    /**
149
+     * @dataProvider dataTestCheckSpecialCharactersFail
150
+     * @param string $password
151
+     * @expectedException \OC\HintException
152
+     */
153
+    public function testCheckSpecialCharactersFail($password) {
154
+        $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn(true);
155
+        $this->passValidator->checkSpecialCharacters($password);
156
+    }
157
+    public function dataTestCheckSpecialCharactersFail() {
158
+        return [
159
+            ['testpass'],
160
+            ['TestPass1'],
161
+            ['TEST2PASS']
162
+        ];
163
+    }
164
+    public function testValidate() {
165
+        $password = 'password';
166
+        $instance = $this->getMockInstance(
167
+            [
168
+                'checkPasswordLength',
169
+                'checkUpperLowerCase',
170
+                'checkNumericCharacters',
171
+                'checkSpecialCharacters',
172
+            ]
173
+        );
174
+        $instance->expects($this->once())->method('checkPasswordLength')->with($password);
175
+        $instance->expects($this->once())->method('checkUpperLowerCase')->with($password);
176
+        $instance->expects($this->once())->method('checkNumericCharacters')->with($password);
177
+        $instance->expects($this->once())->method('checkSpecialCharacters')->with($password);
178
+        $instance->validate($password);
179
+    }
180 180
 }
181 181
\ No newline at end of file
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,9 +23,9 @@
 block discarded – undo
23 23
 }
24 24
 require_once __DIR__.'/../../../lib/base.php';
25 25
 
26
-OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib', true);
26
+OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT.'/tests/lib', true);
27 27
 
28
-if(!class_exists('PHPUnit_Framework_TestCase')) {
28
+if (!class_exists('PHPUnit_Framework_TestCase')) {
29 29
     require_once('PHPUnit/Autoload.php');
30 30
 }
31 31
 
Please login to merge, or discard this patch.
lib/Panels/PersonalPanel.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -25,27 +25,27 @@
 block discarded – undo
25 25
 
26 26
 class PersonalPanel implements ISettings {
27 27
 
28
-	/** @var SecurityConfig */
29
-	private $config;
30
-
31
-	public function __construct(SecurityConfig $config) {
32
-		$this->config = $config;
33
-	}
34
-
35
-	public function getPanel() {
36
-		$params = $this->config->getAllSecurityConfigs();
37
-		$tmpl = new Template('security', 'settings-personal');
38
-		foreach ($params as $key => $value) {
39
-			$tmpl->assign($key, $value);
40
-		}
41
-		return $tmpl;
42
-	}
43
-
44
-	public function getSectionID() {
45
-		return 'general';
46
-	}
47
-
48
-	public function getPriority() {
49
-		return 0;
50
-	}
28
+    /** @var SecurityConfig */
29
+    private $config;
30
+
31
+    public function __construct(SecurityConfig $config) {
32
+        $this->config = $config;
33
+    }
34
+
35
+    public function getPanel() {
36
+        $params = $this->config->getAllSecurityConfigs();
37
+        $tmpl = new Template('security', 'settings-personal');
38
+        foreach ($params as $key => $value) {
39
+            $tmpl->assign($key, $value);
40
+        }
41
+        return $tmpl;
42
+    }
43
+
44
+    public function getSectionID() {
45
+        return 'general';
46
+    }
47
+
48
+    public function getPriority() {
49
+        return 0;
50
+    }
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Panels/AdminPanel.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@
 block discarded – undo
26 26
 
27 27
 class AdminPanel implements ISettings {
28 28
 
29
-	/** @var SecurityConfig */
30
-	private $config;
31
-
32
-	public function __construct(SecurityConfig $config) {
33
-		$this->config = $config;
34
-	}
35
-
36
-	public function getPanel() {
37
-		$params = $this->config->getAllSecurityConfigs();
38
-		$tmpl = new Template('security', 'settings-admin');
39
-		foreach ($params as $key => $value) {
40
-			$tmpl->assign($key, $value);
41
-		}
42
-		return $tmpl;
43
-	}
44
-
45
-	public function getSectionID() {
46
-		return 'security';
47
-	}
48
-
49
-	public function getPriority() {
50
-		return 100;
51
-	}
29
+    /** @var SecurityConfig */
30
+    private $config;
31
+
32
+    public function __construct(SecurityConfig $config) {
33
+        $this->config = $config;
34
+    }
35
+
36
+    public function getPanel() {
37
+        $params = $this->config->getAllSecurityConfigs();
38
+        $tmpl = new Template('security', 'settings-admin');
39
+        foreach ($params as $key => $value) {
40
+            $tmpl->assign($key, $value);
41
+        }
42
+        return $tmpl;
43
+    }
44
+
45
+    public function getSectionID() {
46
+        return 'security';
47
+    }
48
+
49
+    public function getPriority() {
50
+        return 100;
51
+    }
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
lib/PasswordValidator.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -24,115 +24,115 @@
 block discarded – undo
24 24
 
25 25
 class PasswordValidator  {
26 26
 
27
-	/** @var SecurityConfig */
28
-	protected $config;
27
+    /** @var SecurityConfig */
28
+    protected $config;
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * PasswordValidator constructor.
35
-	 *
36
-	 * @param SecurityConfig $config
37
-	 * @param IL10N $l
38
-	 */
39
-	public function __construct(SecurityConfig $config, IL10N $l) {
40
-		$this->config = $config;
41
-		$this->l = $l;
42
-	}
33
+    /**
34
+     * PasswordValidator constructor.
35
+     *
36
+     * @param SecurityConfig $config
37
+     * @param IL10N $l
38
+     */
39
+    public function __construct(SecurityConfig $config, IL10N $l) {
40
+        $this->config = $config;
41
+        $this->l = $l;
42
+    }
43 43
 
44
-	/**
45
-	 * validate the given password satisfies defined password policy
46
-	 *
47
-	 * @param string $password
48
-	 * @throws HintException
49
-	 */
50
-	public function validate($password) {
51
-		$this->checkPasswordLength($password);
52
-		$this->checkNumericCharacters($password);
53
-		$this->checkUpperLowerCase($password);
54
-		$this->checkSpecialCharacters($password);
55
-	}
44
+    /**
45
+     * validate the given password satisfies defined password policy
46
+     *
47
+     * @param string $password
48
+     * @throws HintException
49
+     */
50
+    public function validate($password) {
51
+        $this->checkPasswordLength($password);
52
+        $this->checkNumericCharacters($password);
53
+        $this->checkUpperLowerCase($password);
54
+        $this->checkSpecialCharacters($password);
55
+    }
56 56
 
57
-	/**
58
-	 * validate the given password satisfies defined min length
59
-	 *
60
-	 * @param string $password
61
-	 * @throws HintException
62
-	 */
63
-	public function checkPasswordLength($password) {
64
-		$minPassLength = $this->config->getMinPasswordLength();
65
-		if(strlen($password) < $minPassLength) {
66
-			$message = 'Password needs to be at least ' . $minPassLength . ' characters long';
67
-			$hint = $this->l->t(
68
-				'Password needs to be at least %s characters long', [$minPassLength]
69
-			);
70
-			throw new HintException($message, $hint);
71
-		}
72
-	}
57
+    /**
58
+     * validate the given password satisfies defined min length
59
+     *
60
+     * @param string $password
61
+     * @throws HintException
62
+     */
63
+    public function checkPasswordLength($password) {
64
+        $minPassLength = $this->config->getMinPasswordLength();
65
+        if(strlen($password) < $minPassLength) {
66
+            $message = 'Password needs to be at least ' . $minPassLength . ' characters long';
67
+            $hint = $this->l->t(
68
+                'Password needs to be at least %s characters long', [$minPassLength]
69
+            );
70
+            throw new HintException($message, $hint);
71
+        }
72
+    }
73 73
 
74
-	/**
75
-	 * validate if password contains at least one upper and one lower case character
76
-	 *
77
-	 * @param string $password
78
-	 * @throws HintException
79
-	 */
80
-	public function checkUpperLowerCase($password) {
81
-		$enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced();
82
-		if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
83
-			$message = 'Password should contain at least one upper and one lower case character.';
84
-			$hint = $this->l->t(
85
-				'Password should contain at least one upper and one lower case character.'
86
-			);
87
-			throw new HintException($message, $hint);
88
-		}
89
-	}
74
+    /**
75
+     * validate if password contains at least one upper and one lower case character
76
+     *
77
+     * @param string $password
78
+     * @throws HintException
79
+     */
80
+    public function checkUpperLowerCase($password) {
81
+        $enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced();
82
+        if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
83
+            $message = 'Password should contain at least one upper and one lower case character.';
84
+            $hint = $this->l->t(
85
+                'Password should contain at least one upper and one lower case character.'
86
+            );
87
+            throw new HintException($message, $hint);
88
+        }
89
+    }
90 90
 
91
-	/**
92
-	 * validate the given password satisfies numeric character policy
93
-	 *
94
-	 * @param string $password
95
-	 * @throws HintException
96
-	 */
97
-	public function checkNumericCharacters($password) {
98
-		$enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced();
99
-		if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
100
-			$message = 'Password should contain at least one numerical character.';
101
-			$hint = $this->l->t(
102
-				'Password should contain at least one numerical character.'
103
-			);
104
-			throw new HintException($message, $hint);
105
-		}
106
-	}
91
+    /**
92
+     * validate the given password satisfies numeric character policy
93
+     *
94
+     * @param string $password
95
+     * @throws HintException
96
+     */
97
+    public function checkNumericCharacters($password) {
98
+        $enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced();
99
+        if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
100
+            $message = 'Password should contain at least one numerical character.';
101
+            $hint = $this->l->t(
102
+                'Password should contain at least one numerical character.'
103
+            );
104
+            throw new HintException($message, $hint);
105
+        }
106
+    }
107 107
 
108
-	/**
109
-	 * check if password contains at least one special character
110
-	 *
111
-	 * @param string $password
112
-	 * @throws HintException
113
-	 */
114
-	public function checkSpecialCharacters($password) {
115
-		$enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced();
116
-		if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
117
-			$message = 'Password should contain at least one special character.';
118
-			$hint = $this->l->t(
119
-				'Password should contain at least one special character.'
120
-			);
121
-			throw new HintException($message, $hint);
122
-		}
123
-	}
108
+    /**
109
+     * check if password contains at least one special character
110
+     *
111
+     * @param string $password
112
+     * @throws HintException
113
+     */
114
+    public function checkSpecialCharacters($password) {
115
+        $enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced();
116
+        if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
117
+            $message = 'Password should contain at least one special character.';
118
+            $hint = $this->l->t(
119
+                'Password should contain at least one special character.'
120
+            );
121
+            throw new HintException($message, $hint);
122
+        }
123
+    }
124 124
 
125
-	public function hasNumericalCharacters($password) {
126
-		return preg_match('/\d/', $password) === 1 ? true : false;
127
-	}
125
+    public function hasNumericalCharacters($password) {
126
+        return preg_match('/\d/', $password) === 1 ? true : false;
127
+    }
128 128
 
129
-	public function hasUpperAndLowerCase($password) {
130
-		$toLower = strtolower($password);
131
-		$toUpper = strtoupper($password);
132
-		return ($toLower !== $password && $toUpper !== $password) ? true : false;
133
-	}
129
+    public function hasUpperAndLowerCase($password) {
130
+        $toLower = strtolower($password);
131
+        $toUpper = strtoupper($password);
132
+        return ($toLower !== $password && $toUpper !== $password) ? true : false;
133
+    }
134 134
 
135
-	public function hasSpecialCharacter($password) {
136
-		return (!ctype_alnum($password));
137
-	}
135
+    public function hasSpecialCharacter($password) {
136
+        return (!ctype_alnum($password));
137
+    }
138 138
 }
139 139
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 use OC\HintException;
23 23
 use OCP\IL10N;
24 24
 
25
-class PasswordValidator  {
25
+class PasswordValidator {
26 26
 
27 27
 	/** @var SecurityConfig */
28 28
 	protected $config;
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function checkPasswordLength($password) {
64 64
 		$minPassLength = $this->config->getMinPasswordLength();
65
-		if(strlen($password) < $minPassLength) {
66
-			$message = 'Password needs to be at least ' . $minPassLength . ' characters long';
65
+		if (strlen($password) < $minPassLength) {
66
+			$message = 'Password needs to be at least '.$minPassLength.' characters long';
67 67
 			$hint = $this->l->t(
68 68
 				'Password needs to be at least %s characters long', [$minPassLength]
69 69
 			);
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @throws HintException
79 79
 	 */
80 80
 	public function checkUpperLowerCase($password) {
81
-		$enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced();
82
-		if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
81
+		$enforceUpperLowerCase = $this->config->getIsUpperLowerCaseEnforced();
82
+		if ($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
83 83
 			$message = 'Password should contain at least one upper and one lower case character.';
84 84
 			$hint = $this->l->t(
85 85
 				'Password should contain at least one upper and one lower case character.'
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function checkNumericCharacters($password) {
98 98
 		$enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced();
99
-		if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
99
+		if ($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
100 100
 			$message = 'Password should contain at least one numerical character.';
101 101
 			$hint = $this->l->t(
102 102
 				'Password should contain at least one numerical character.'
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function checkSpecialCharacters($password) {
115 115
 		$enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced();
116
-		if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
116
+		if ($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
117 117
 			$message = 'Password should contain at least one special character.';
118 118
 			$hint = $this->l->t(
119 119
 				'Password should contain at least one special character.'
Please login to merge, or discard this patch.
lib/Controller/SettingsController.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -26,23 +26,23 @@
 block discarded – undo
26 26
 
27 27
 class SettingsController extends Controller {
28 28
 
29
-	/** @var SecurityConfig */
30
-	private $config;
29
+    /** @var SecurityConfig */
30
+    private $config;
31 31
 
32
-	/**
33
-	 * @param string $appName
34
-	 * @param IRequest $request
35
-	 * @param SecurityConfig $config
36
-	 */
37
-	public function __construct($appName, IRequest $request, SecurityConfig $config) {
38
-		parent::__construct($appName, $request);
39
-		$this->config = $config;
40
-	}
32
+    /**
33
+     * @param string $appName
34
+     * @param IRequest $request
35
+     * @param SecurityConfig $config
36
+     */
37
+    public function __construct($appName, IRequest $request, SecurityConfig $config) {
38
+        parent::__construct($appName, $request);
39
+        $this->config = $config;
40
+    }
41 41
 
42
-	/**
43
-	 * @return array
44
-	 */
45
-	public function state() {
46
-		return $this->config->getAllSecurityConfigs();
47
-	}
42
+    /**
43
+     * @return array
44
+     */
45
+    public function state() {
46
+        return $this->config->getAllSecurityConfigs();
47
+    }
48 48
 }
Please login to merge, or discard this patch.
lib/AppInfo/Application.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 
32 32
 class Application extends App {
33 33
 
34
-    public function __construct(array $urlParams=array()){
34
+    public function __construct(array $urlParams = array()) {
35 35
         parent::__construct('security', $urlParams);
36 36
 
37 37
         $container = $this->getContainer();
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
                 $c->query('DbService'),
48 48
                 $c->query('SecurityConfig'),
49 49
                 $c->query('OCP\IL10N'),
50
-				$c->query('OCP\AppFramework\Utility\ITimeFactory')
50
+                $c->query('OCP\AppFramework\Utility\ITimeFactory')
51 51
             );
52 52
         });
53 53
 
Please login to merge, or discard this patch.
lib/Db/DbService.php 2 patches
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-
4 3
  *
5 4
  * @author Semih Serhat Karakaya
6 5
  * @copyright Copyright (c) 2017, ownCloud GmbH
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @param string $uid
64 64
      */
65
-    public function addFailedLoginAttempt($uid, $ip){
65
+    public function addFailedLoginAttempt($uid, $ip) {
66 66
         $builder = $this->connection->getQueryBuilder();
67 67
         $builder->insert('failed_login_attempts')
68 68
             ->setValue('ip', $builder->createNamedParameter($ip))
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function getSuspiciousActivityCountForUidIpCombination($uid, $ip) {
80 80
         $builder = $this->connection->getQueryBuilder();
81
-        $thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
81
+        $thresholdTime = (new \DateTime())->modify("-".$this->config->getBruteForceProtectionTimeThreshold()."second")->getTimestamp();
82 82
         $attempts = $builder->selectAlias($builder->createFunction('COUNT(*)'), 'count')
83 83
             ->from('failed_login_attempts')
84 84
             ->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     public function getSuspiciousActivityCountForUid($uid) {
97 97
         $builder = $this->connection->getQueryBuilder();
98
-        $thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
98
+        $thresholdTime = (new \DateTime())->modify("-".$this->config->getBruteForceProtectionTimeThreshold()."second")->getTimestamp();
99 99
         $attempts = $builder->selectAlias($builder->createFunction('COUNT(*)'), 'count')
100 100
             ->from('failed_login_attempts')
101 101
             ->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function getSuspiciousActivityCountForIp($ip) {
113 113
         $builder = $this->connection->getQueryBuilder();
114
-        $thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
114
+        $thresholdTime = (new \DateTime())->modify("-".$this->config->getBruteForceProtectionTimeThreshold()."second")->getTimestamp();
115 115
         $attempts = $builder->selectAlias($builder->createFunction('COUNT(*)'), 'count')
116 116
             ->from('failed_login_attempts')
117 117
             ->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getLastFailedLoginAttemptTimeForIp($ip) {
129 129
         $builder = $this->connection->getQueryBuilder();
130
-        $thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
130
+        $thresholdTime = (new \DateTime())->modify("-".$this->config->getBruteForceProtectionTimeThreshold()."second")->getTimestamp();
131 131
         $lastAttempt = $builder->select('attempted_at')
132 132
             ->from('failed_login_attempts')
133 133
             ->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
134 134
             ->andWhere($builder->expr()->eq('ip', $builder->createNamedParameter($ip)))
135
-            ->orderBy('attempted_at','DESC')
135
+            ->orderBy('attempted_at', 'DESC')
136 136
             ->setMaxResults(1)
137 137
             ->execute()
138 138
             ->fetch();
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     public function deleteSuspiciousAttemptsForIp($ip) {
146 146
         $builder = $this->connection->getQueryBuilder();
147 147
         $builder->delete('failed_login_attempts')
148
-            ->where($builder->expr()->eq('ip',$builder->createNamedParameter($ip)))
148
+            ->where($builder->expr()->eq('ip', $builder->createNamedParameter($ip)))
149 149
             ->execute();
150 150
     }
151 151
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     public function deleteSuspiciousAttemptsForUidIpCombination($uid, $ip) {
157 157
         $builder = $this->connection->getQueryBuilder();
158 158
         $builder->delete('failed_login_attempts')
159
-            ->where($builder->expr()->eq('uid',$builder->createNamedParameter($uid)))
159
+            ->where($builder->expr()->eq('uid', $builder->createNamedParameter($uid)))
160 160
             ->andWhere($builder->expr()->eq('ip', $builder->createNamedParameter($ip)))
161 161
             ->execute();
162 162
     }
Please login to merge, or discard this patch.