| @@ 780-827 (lines=48) @@ | ||
| 777 | * @throws InvalidArgumentException If the password is invalid. |
|
| 778 | * @return boolean Returns TRUE if the password was changed, or FALSE otherwise. |
|
| 779 | */ |
|
| 780 | public function rehashUserPassword(AuthenticatableInterface $user, $password, $update = true) |
|
| 781 | { |
|
| 782 | if (!$this->validateAuthPassword($password)) { |
|
| 783 | throw new InvalidArgumentException( |
|
| 784 | 'Can not rehash password: password is invalid' |
|
| 785 | ); |
|
| 786 | } |
|
| 787 | ||
| 788 | $userId = $user->getAuthId(); |
|
| 789 | ||
| 790 | if ($update && $userId) { |
|
| 791 | $userClass = get_class($user); |
|
| 792 | ||
| 793 | $this->logger->info(sprintf( |
|
| 794 | '[Authenticator] Rehashing password for user "%s" (%s)', |
|
| 795 | $userId, |
|
| 796 | $userClass |
|
| 797 | )); |
|
| 798 | } |
|
| 799 | ||
| 800 | $passwordKey = $user->getAuthPasswordKey(); |
|
| 801 | ||
| 802 | $user[$passwordKey] = password_hash($password, PASSWORD_DEFAULT); |
|
| 803 | ||
| 804 | if ($update && $userId) { |
|
| 805 | $result = $user->update([ |
|
| 806 | $passwordKey, |
|
| 807 | ]); |
|
| 808 | ||
| 809 | if ($result) { |
|
| 810 | $this->logger->notice(sprintf( |
|
| 811 | '[Authenticator] Password was rehashed for user "%s" (%s)', |
|
| 812 | $userId, |
|
| 813 | $userClass |
|
| 814 | )); |
|
| 815 | } else { |
|
| 816 | $this->logger->warning(sprintf( |
|
| 817 | '[Authenticator] Password failed to be rehashed for user "%s" (%s)', |
|
| 818 | $userId, |
|
| 819 | $userClass |
|
| 820 | )); |
|
| 821 | } |
|
| 822 | ||
| 823 | return $result; |
|
| 824 | } |
|
| 825 | ||
| 826 | return true; |
|
| 827 | } |
|
| 828 | ||
| 829 | /** |
|
| 830 | * Updates the user's password hash. |
|
| @@ 838-885 (lines=48) @@ | ||
| 835 | * @throws InvalidArgumentException If the password is invalid. |
|
| 836 | * @return boolean Returns TRUE if the password was changed, or FALSE otherwise. |
|
| 837 | */ |
|
| 838 | public function changeUserPassword(AuthenticatableInterface $user, $password, $update = true) |
|
| 839 | { |
|
| 840 | if (!$this->validateAuthPassword($password)) { |
|
| 841 | throw new InvalidArgumentException( |
|
| 842 | 'Can not change password: password is invalid' |
|
| 843 | ); |
|
| 844 | } |
|
| 845 | ||
| 846 | $userId = $user->getAuthId(); |
|
| 847 | ||
| 848 | if ($update && $userId) { |
|
| 849 | $userClass = get_class($user); |
|
| 850 | ||
| 851 | $this->logger->info(sprintf( |
|
| 852 | '[Authenticator] Changing password for user "%s" (%s)', |
|
| 853 | $userId, |
|
| 854 | $userClass |
|
| 855 | )); |
|
| 856 | } |
|
| 857 | ||
| 858 | $passwordKey = $user->getAuthPasswordKey(); |
|
| 859 | ||
| 860 | $user[$passwordKey] = password_hash($password, PASSWORD_DEFAULT); |
|
| 861 | ||
| 862 | if ($update && $userId) { |
|
| 863 | $result = $user->update([ |
|
| 864 | $passwordKey, |
|
| 865 | ]); |
|
| 866 | ||
| 867 | if ($result) { |
|
| 868 | $this->logger->notice(sprintf( |
|
| 869 | '[Authenticator] Password was changed for user "%s" (%s)', |
|
| 870 | $userId, |
|
| 871 | $userClass |
|
| 872 | )); |
|
| 873 | } else { |
|
| 874 | $this->logger->warning(sprintf( |
|
| 875 | '[Authenticator] Password failed to be changed for user "%s" (%s)', |
|
| 876 | $userId, |
|
| 877 | $userClass |
|
| 878 | )); |
|
| 879 | } |
|
| 880 | ||
| 881 | return $result; |
|
| 882 | } |
|
| 883 | ||
| 884 | return true; |
|
| 885 | } |
|
| 886 | ||
| 887 | /** |
|
| 888 | * Clear the authenticator's internal cache. |
|