User login programmatically with username and password

Public

can be helpful while creating user pro grammatically and login user after successfull account creating

</> CopyGet raw version
php
  1. /**
  2.  * Helper function to login a user after registration.
  3.  * needs username and password as parameter.
  4.  */
  5. function mymodule_user_login_credentials($username, $password) {
  6. if (user_authenticate($username, $password)) {
  7. $user_obj = user_load_by_name($username);
  8. $form_state = array();
  9. $form_state['uid'] = $user_obj->uid;
  10. user_login_submit(array(), $form_state);
  11. return true;
  12. }
  13. else {
  14. return false;
  15. }
  16. }

Comments

kienan's picture

if password user wrong ?