Skip to content

Commit cb54ddc

Browse files
committed
45 Verify if the username is an e-mail and avoid big usernames
1 parent 1a7a297 commit cb54ddc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

classes/BadpwFailedLoginsDAO.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use PKP\db\DAO;
1212
use APP\plugins\generic\betterPassword\classes\BadpwFailedLogins as BadpwFailedLogins;
13+
use APP\facades\Repo;
1314

1415
class BadpwFailedLoginsDAO extends DAO {
1516
/**
@@ -58,6 +59,17 @@ public function deleteObject(BadpwFailedLogins $badpwObj) : bool {
5859
* @return BadpwFailedLogins object Object matching the username
5960
*/
6061
public function getByUsername(string $username) : ?BadpwFailedLogins {
62+
// Verify if the username is an email
63+
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
64+
$user = Repo::user()->getByEmail($username);
65+
if (!$user) {
66+
return null;
67+
}
68+
$username = $user->getData('userName');
69+
} elseif (strlen($username) > 32) { // Invalid username length
70+
return null;
71+
}
72+
6173
$result = $this->retrieve('
6274
SELECT *
6375
FROM badpw_failedlogins

0 commit comments

Comments
 (0)