Title: Automatic login
Last modified: August 19, 2016

---

# Automatic login

 *  [Nicklas](https://wordpress.org/support/users/blekfis/)
 * (@blekfis)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-login/)
 * I was looking for a way to login automatically and found [this piece of code](http://www.lbsharp.com/wordpress/index.php/2007/12/10/wordpress-auto-login/)
   that I adjusted to suit my needs.
 * I wanted to be able to login as admin via an URL (mostly to be able to easily
   run upgrades of all my sites). But the code I found would login every visitor
   as admin – NOT what I was looking for… So I changed it slightly to be more secure:
 * Insert the following to your functions.php
 *     ```
       function auto_login() {
           if (!is_user_logged_in()) {
               $user_login = $_GET['YOUR-OWN-SECRET-KEY'];
               $user = get_userdatabylogin($user_login);
               $user_id = $user->ID;
               wp_set_current_user($user_id, $user_login);
               wp_set_auth_cookie($user_id);
               do_action('wp_login', $user_login);
           }
       }
       add_action('init', 'auto_login');
       ```
   
 * Change YOUR-OWN-SECRET-KEY to something that’s not easy to find out, any [password creator](http://maord.com)
   would help you with this.
 * Then just make a list of URLs to suit your needs. To go to WP-admin upgrade page,
   URL looks like:
    [http://www.domain.com/wp-admin/update-core.php?YOUR-OWN-SECRET-KEY=admin](http://www.domain.com/wp-admin/update-core.php?YOUR-OWN-SECRET-KEY=admin)
   That is if your admin account login is ‘admin’ (I suggest you change this due
   to security!)
 * Now I need to find out how to actually start the upgrade via an URL – but maybe
   someone else knows how to make that happen…?
 * Tried adding action=do-core-upgrade, but failed…

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [shuu](https://wordpress.org/support/users/shuu/)
 * (@shuu)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-login/#post-1282438)
 * hi blekfis,
    unfortunately I can’t answer your question but I would really like
   to ask you one. Your modification to the code is almost exactly what I want to
   do. I want to have it so a user can auto-login using their wordpress username
   and password.
 * Is there anyways to change that hardcoded secret key into the variable which 
   checks for the user’s actual password instead?
 * I tried checking the original source for the code but I don’t see any variable
   in the newest version to check the user password.
 *  Thread Starter [Nicklas](https://wordpress.org/support/users/blekfis/)
 * (@blekfis)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/automatic-login/#post-1282455)
 * I’m sure it’s doable, I just don’t know how – I’m just a cut-n-paste coder…
 * I hope someone skilled will answer both of our questions 🙂
 *  [Zambrano Sergio](https://wordpress.org/support/users/sergiozambrano/)
 * (@sergiozambrano)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/automatic-login/#post-1282518)
 * If there were a way to do that on your server (where wordpress is running) you’ll
   have found the worst pishing tool for wordpress!!
 * Can you imagine the wordpress password being able to be accessed from anyone’s
   wordpress?
 * If you meant “their own credentials for your site while they are on their personal
   computer, probably already-logged-in”… you wouldn’t need that code, since their
   computer would just remember their login info (cookies)
 * Let me know if you found the answer, please.
    That could help me with my recent
   question: [http://wordpress.org/support/topic/353561?replies=1#post-1356116](http://wordpress.org/support/topic/353561?replies=1#post-1356116)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Automatic login’ is closed to new replies.

## Tags

 * [auto](https://wordpress.org/support/topic-tag/auto/)
 * [autologin](https://wordpress.org/support/topic-tag/autologin/)
 * [login](https://wordpress.org/support/topic-tag/login/)

 * 3 replies
 * 3 participants
 * Last reply from: [Zambrano Sergio](https://wordpress.org/support/users/sergiozambrano/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/automatic-login/#post-1282518)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
