6 * Support for authentication of encrypted hash in a global setting
9 * @link https://www.open-emr.org
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2019-2020 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 namespace OpenEMR\Common\Auth
;
17 use OpenEMR\Common\Crypto\CryptoGen
;
24 private $globalSetting;
26 public function __construct($globalSetting)
28 $this->globalSetting
= $globalSetting;
31 public function globalVerify(string $pass): bool
33 if (empty($pass) ||
empty($this->globalSetting
) ||
empty($GLOBALS[$this->globalSetting
])) {
37 // collect and decrypt the global hash
38 $cryptoGen = new CryptoGen();
39 $globalHash = $cryptoGen->decryptStandard($GLOBALS[$this->globalSetting
]);
41 if (empty($globalHash)) {
46 if ((!AuthHash
::hashValid($globalHash)) ||
(!AuthHash
::passwordVerify($pass, $globalHash))) {
50 // success, now rehash if needed
51 $authHash = new AuthHash();
52 if ($authHash->passwordNeedsRehash($globalHash)) {
53 $newHash = $authHash->passwordHash($pass);
54 $newHash = $cryptoGen->encryptStandard($newHash);
55 sqlStatement("UPDATE `globals` SET `gl_value` = ? WHERE `gl_name` = ?", [$newHash, $this->globalSetting
]);