From f5471b0f2b310e112d1615e179ac7cafc1559343 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sun, 24 Oct 2021 22:00:59 +0200 Subject: [PATCH] Renamed and updated the password helper --- ...general_helper.php => password_helper.php} | 42 +++---------------- 1 file changed, 6 insertions(+), 36 deletions(-) rename application/helpers/{general_helper.php => password_helper.php} (67%) diff --git a/application/helpers/general_helper.php b/application/helpers/password_helper.php similarity index 67% rename from application/helpers/general_helper.php rename to application/helpers/password_helper.php index 407d6b9a..72c652dc 100644 --- a/application/helpers/general_helper.php +++ b/application/helpers/password_helper.php @@ -11,39 +11,6 @@ * @since v1.0.0 * ---------------------------------------------------------------------------- */ -/** - * Get date in RFC3339 - * - * For example used in XML/Atom - * - * @link http://stackoverflow.com/questions/5671433/php-time-to-google-calendar-dates-time-format - * - * @param integer $timestamp - * - * @return string date in RFC3339 - * - * @author Boris Korobkov - */ -function date3339($timestamp = 0) -{ - if ( ! $timestamp) - { - $timestamp = time(); - } - $date = date('Y-m-d\TH:i:s', $timestamp); - - $matches = []; - if (preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $timestamp), $matches)) - { - $date .= $matches[1] . $matches[2] . ':' . $matches[3]; - } - else - { - $date .= 'Z'; - } - return $date; -} - /** * Generate a hash of password string. * @@ -51,14 +18,15 @@ function date3339($timestamp = 0) * hashed password. * * @param string $salt Salt value for current user. This value is stored on the database and is used when generating - * the password hash. + * the password hashes. * @param string $password Given string password. * * @return string Returns the hash string of the given password. */ -function hash_password($salt, $password) +function hash_password(string $salt, string $password): string { $half = (int)(strlen($salt) / 2); + $hash = hash('sha256', substr($salt, 0, $half) . $password . substr($salt, $half)); for ($i = 0; $i < 100000; $i++) @@ -77,9 +45,11 @@ function hash_password($salt, $password) * * @return string Returns a salt string. */ -function generate_salt() +function generate_salt(): string { $max_length = 100; + $salt = hash('sha256', (uniqid(rand(), TRUE))); + return substr($salt, 0, $max_length); }