-
Notifications
You must be signed in to change notification settings - Fork 10
/
pluggable.php
102 lines (86 loc) · 2.73 KB
/
pluggable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* This file is part of the Passwords Evolved WordPress plugin.
*
* (c) Carl Alexander <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PasswordsEvolved\Password\Generator\PasswordGeneratorInterface;
/**
* Pluggable functions used by the Passwords Evolved plugin.
*
* @author Carl Alexander <[email protected]>
*/
if (!function_exists('wp_check_password')) {
/**
* Checks the given plaintext password against the given encrypted password hash.
*
* @param string $password
* @param string $hash
* @param int $user_id
*
* @return bool
*/
function wp_check_password($password, $hash, $user_id = null)
{
global $passwords_evolved;
$hasher = $passwords_evolved->get_password_hasher();
$check = $hasher->is_password_valid($password, $hash);
if ($user_id && $check && !$hasher->is_hash_valid($hash)) {
$hash = wp_set_password($password, $user_id);
}
return apply_filters('check_password', $check, $password, $hash, $user_id);
}
}
if (!function_exists('wp_generate_password')) {
/**
* Generates a random password that hasn't been compromised.
*
* @param int $length
* @param bool $special_chars
* @param bool $extra_special_chars
*
* @return string
*/
function wp_generate_password($length = PasswordGeneratorInterface::MIN_LENGTH, $special_chars = true, $extra_special_chars = false)
{
global $passwords_evolved;
$password = $passwords_evolved->get_password_generator()->generate_password($length, $special_chars, $extra_special_chars);
return apply_filters('random_password', $password);
}
}
if (!function_exists('wp_hash_password')) {
/**
* Create a hash of the given plain text password.
*
* @param string $password
*
* @return string
*/
function wp_hash_password($password)
{
global $passwords_evolved;
return $passwords_evolved->get_password_hasher()->hash_password(trim($password));
}
}
if (!function_exists('wp_set_password')) {
/**
* Set a new encrypted password for the user with the given user ID
* using the given plain text password.
*
* @param string $password
* @param int $user_id
*
* @return string
*/
function wp_set_password($password, $user_id)
{
global $wpdb;
$hash = wp_hash_password($password);
$wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id));
wp_cache_delete($user_id, 'users');
return $hash;
}
}