Skip to content

Commit

Permalink
A TP should only include digits 0-9 and have a length of 12 characters
Browse files Browse the repository at this point in the history
In addition, a TP may not start with a leading 0
  • Loading branch information
Leon Klingele committed Aug 3, 2017
1 parent fa7edac commit 7b87072
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions security/temporarypasswordmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class TemporaryPasswordManager {
private $hashFuncName = 'sha256';
private $maxUserLength = 64; // Keep in sync with database.xml
private $disallowedUserChars = array(':', '/');
private $temporaryPasswordLength = 10; // ld(55^10) ≈ 58 bit of entropy
private $temporaryPasswordAllowedChars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ123456789';
private $temporaryPasswordLength = 12;
private $temporaryPasswordAllowedChars = '0123456789';

public function __construct(IDBConnection $db) {
$this->db = $db;
Expand All @@ -36,7 +36,10 @@ private function hashTemporaryPassword($tp) {
}

private function getNewTemporaryPassword() {
return Security::getRandomString($this->temporaryPasswordLength, $this->temporaryPasswordAllowedChars);
do {
$pass = Security::getRandomString($this->temporaryPasswordLength, $this->temporaryPasswordAllowedChars);
} while ($pass[0] === '0'); // Make sure we don't have a leading 0
return $pass;
}

private function requireEnabledTemporaryPassword() {
Expand Down

0 comments on commit 7b87072

Please sign in to comment.