I am programatically creating user with this code:
$new_user = array( 'name' => $state['unique_name'], 'mail' => $state['values']['email'], 'pass' => $state['values']['password'], 'status' => 1, 'init' => $state['values']['email'], 'roles' => array($role->rid => $role->name), ); $account = user_save(NULL, $new_user); _user_mail_notify('register_pending_approval', $account);
This code is creating user and should send verification email, after which user should be able to log in. Problem is that users are able to log in immediately.
Please note that I work on localhost and cannot send email from localhost. I will have very little time to test site on real server, so I would like to know the solution in advance.
The solution could be this approach:
The only way I was able to accomplish this was by setting the users' status to 0, then sending a custom email with a link to a custom verification page. The link contains the ID of the user and a hash of a private key concatenated with the user's email. On the verification page, I pull the user's email from the database based on the ID in the URL, concatenate the private key to the email and hash it, if the hash matches the hash in the URL, I set the user's status to 1, enabling the user to login.
But the next question is how to generate that "private key" from user database datas and from email link. I can't see any private key of user in drupal database.