Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add max password length constant
  • Loading branch information
alextselegidis committed May 9, 2022
1 parent 63dbb51 commit e3d3673
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/config/constants.php
Expand Up @@ -79,6 +79,7 @@
define('TIME_FORMAT_MILITARY', 'military');

define('MIN_PASSWORD_LENGTH', 7);
define('MAX_PASSWORD_LENGTH', 100);
define('ANY_PROVIDER', 'any-provider');

define('CALENDAR_VIEW_DEFAULT', 'default');
Expand Down
7 changes: 7 additions & 0 deletions application/helpers/password_helper.php
Expand Up @@ -22,9 +22,16 @@
* @param string $password Given string password.
*
* @return string Returns the hash string of the given password.
*
* @throws Exception
*/
function hash_password(string $salt, string $password): string
{
if (strlen($password) > MAX_PASSWORD_LENGTH)
{
throw new Exception('The provided password is too long, please use a shorter value.');
}

$half = (int)(strlen($salt) / 2);

$hash = hash('sha256', substr($salt, 0, $half) . $password . substr($salt, $half));
Expand Down

0 comments on commit e3d3673

Please sign in to comment.