| 7 password.inc | user_hash_password($password, $count_log2 = 0) |
| 8 password.inc | user_hash_password($password, $count_log2 = 0) |
Hash a password using a secure hash.
Parameters
$password: A plain-text password.
$count_log2: Optional integer to specify the iteration count. Generally used only during mass operations where a value less than the default is needed for speed.
Return value
A string containing the hashed password (and a salt), or FALSE on failure.
5 calls to user_hash_password()
File
- includes/
password.inc, line 207 - Secure password hashing functions for user authentication.
Code
function user_hash_password($password, $count_log2 = 0) {
if (empty($count_log2)) {
// Use the standard iteration count.
$count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT);
}
return _password_crypt('sha512', $password, _password_generate_salt($count_log2));
}
Login or register to post comments
Comments
So how can I use this?
I need to use this in my script that talks to the users table; it's not an actual drupal script.
I have a password in a $password variable.
I tried doing this and got a fatal error:
// insert into Drupal's users and roles for access
function user_hash_password($password, $count_log2 = 0) {
if (empty($count_log2)) {
// Use the standard iteration count.
$count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT);
}
return _password_crypt('sha512', $password, _password_generate_salt($count_log2));
}
$password=user_hash_password($password);
This returned the following error: Fatal error: Call to undefined function variable_get() in /home/content/30/9119230/html/updateorders.php on line 88
Where are you calling
Where are you calling user_hash_password()?
From your sample it looks like your calling it inside a custom script that you have inside the root directory, where you've just copied and pasted the code for user_hash_password. If that's the case, then you need to include includes/bootstrap.inc and then call drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); so that a connection to the database is made, and so that all the necessary files are included (like the one that includes the function variable_get()).
But really at that point it would make more sense to write your own module. If what you need is simple, you could just place a hook_init() function inside the user module and put your code in there. Hook_init() will get called once all the files are loaded.