Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Moving from a non WordPress site to a WordPress Site – Login between both sites

WordPress’s code to verify passwords is wp_check_password. You’ll see that this uses phpass:

require_once ABSPATH . WPINC . '/class-phpass.php';
// By default, use the portable hash from phpass.
$wp_hasher = new PasswordHash( 8, true );

$check = $wp_hasher->CheckPassword( $password, $hash );

which is class-phpass.php in the WordPress code which at first glance looks like it has no WordPress function dependencies and you can just take the whole file.

Note though that you can also modify this code to match your existing passwords if you have them available to WordPress somehow: you could either

  1. add your own authenticate hook, like the default wp_authenticate_username_password

    // Default authentication filters.
    add_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
    

    that would check your own password hash and return a populated WP_User object if it matches

  2. hook the check_password filter, which is called at the end of wp_check_password after it has tested the hash:

    /**
      * Filters whether the plaintext password matches the encrypted password.
      *
      * @since 2.5.0
      *
      * @param bool       $check    Whether the passwords match.
      * @param string     $password The plaintext password.
      * @param string     $hash     The hashed password.
      * @param string|int $user_id  User ID. Can be empty.
      */
     return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    

    If the $check value passed in is false then that means the password didn’t match the hash using WordPress’s algorithm: you could then test the password against the hash using your existing logic and return true if it matches that.

That way your users could keep their existing passwords. Your code that matches the existing hashes could then write a new-style hash into the user object if you wanted since it has the clear password to hand, or you could just keep matching the existing passwords.

The code to check the cookies is a bit more involved, alas. It’s wp_validate_auth_cookie. If you follow this through, you’ll see that

  • the cookie is called wordpress_<hash> or wordpress_sec_<hash>, depending on whether you’re using HTTPS or not, where the hash part is the MD5 of the site URL
  • it is split into four pipe-separated parts
    • username
    • expiration date
    • session token – must match a value in the ‘session_tokens’ wp_usermeta for the user
    • authenticated hash – an MD5-HMAC of the other three components, plus four characters from the user’s password hash (so that cookies are invalidated on password changes), using either AUTH_KEY or SECURE_AUTH_KEY from wp-config as the HMAC key

I suspect you’d do best extracting the relevant parts of the WordPress code rather than trying to reimplement this, or even calling out to the WordPress instance somehow.

However once again you can extend WordPress to accept your existing cookies too: in this case you want to hook determine_current_user.

Related Posts:

  1. Is there a is_user_logged_in() for multisite?
  2. Unable to login to new custom domain on multisite?
  3. share login/logout sessions across two installs?
  4. How to Login Once to an Entire WP Multisite Network
  5. Multisite – Redirect All Users to Subsite Home Page on Subsite Login
  6. WordPress Multisite Login Access
  7. Subdomain login problems
  8. WordPress Multisite local: wp-login.php refreshes on login Chrome Browser
  9. ‘Remote Login’ with MultiSite Domain Mapping still forcing users to login to all blogs individually?
  10. How to stay logged in on a multisite with different domains?
  11. Login on Multiple Sub-Domains without Multisite
  12. Fresh Multisite Install – Can’t Log In
  13. Auto Redirect after login
  14. WordPress MultiSite login to the respective site
  15. How to fix blocked cookies error that doesn’t let me log into wp-admin?
  16. Good way to block users within a multisite setup without deleting them?
  17. Automatically login user across multisite
  18. How can you override the is_multisite check in wp-login.php for individual login/registration?
  19. How to write RewriteRule for login in multisite
  20. Multisite Login problem
  21. Https and Http Login Issue on WordPress Multisite
  22. Different Domains in Multisite Setup
  23. Multisite infinite redirect loop
  24. Disable site visiting and user logins excepting for a specific user
  25. Infamous admin login redirect
  26. Is there something I need to know in order to use WordPress on foreign (Swedish) TLDs?
  27. Restrict users of site 1 to login in site 2 in wordpress multisite
  28. Unable to execute Ajax request, status code 400
  29. How to display custom logo on WordPress login page
  30. WordPress Multisite: Login to all subsites at once
  31. Multisite – site user limited only for this site
  32. Unable to sign in to network after moveing address but able to login into child sites
  33. User not staying logged into one of sub sites in multisite after SSL
  34. Single sign on to sub-sites in Multisite Network
  35. WordPress automatic Login on other page?
  36. how to make a cronjob run, when user needs to be logged in
  37. WordPress Network with SSL for multiple domains
  38. Why does this multisite redirection loop vanish when I add “www.”?
  39. One login for 3 WordPress installations with combined user table doesn’t work
  40. Multisite: Redirect Subsite Administrator to Subsite Home Page, Bypassing Dashboard
  41. Admin user getting redirected to /wp-admin/user
  42. How to login a user with wp_set_auth_cookie on a specific blog within a multisite environment
  43. Is it possible to create a login for restricted visibility?
  44. How do I combine wp_redirect and add_filter?
  45. Some Subdomains on a Multisite Install Not Found
  46. Common login for websites belonging in different networks
  47. Best Way to Setup a Network of WP Sites?
  48. WordPress Multisite restict user access
  49. Error Message when logging into WordPress on Xampp
  50. WordPress MU: Cookie error when trying to login on network WP instance
  51. something in database is causing me to not be able to log into network admin of multisite
  52. How to share WordPress core library
  53. Change wordpress Multisite default site from side id 1 to side id 2
  54. How can I have network sites not use year/month folders by default?
  55. Why can’t a WordPress network (multisite) in it’s own folder use subdomains?
  56. Two-level multisites in WordPress
  57. Display custom homepage text based on domain
  58. Add new domain to ‘My Sites’ using network admin
  59. Switch_to_blog() outside wordpress
  60. Jetpack Blog Subscriptions on Multisite [closed]
  61. current_user_can(‘Administrator’) does not return true in multisite if user is Administrator but NOT Super Admin
  62. cant enable theme in multisite
  63. Default content for a new site in multi site
  64. Proper Network Activation problem has been fixed in wp 3.3.1 or not?
  65. wordpress htaccess is hijacking my .mp4 files
  66. Is there a way to separate a site inside a network (multisite) into its own wp site?
  67. Why is ‘is_multisite’ returning true when it’s a single install?
  68. Forcing SSL Protocol for Multisite Subdomain Child Sites + cPanel Configuration
  69. Website DR using Multisite
  70. Multisite Network menu links not updating
  71. WPML tables not deleted when removing multisite subsite, need help clearing up my sql-file! [closed]
  72. What sites are you registered to when joining a multisite?
  73. How to redirect one page on the subdomain
  74. How to configure Multisite Network with randomized hostnames?
  75. wp_insert_site() is triggering database error in a unit test
  76. Is the Multi site functionality a viable option for Country and Language targeting?
  77. Create a page for a theme only
  78. Multisite – One Site with multiple URLs
  79. Delete all user’s meta without knowing all the ‘key’
  80. How to modify wp_config file for set up subdirectory?
  81. Activation Account Email
  82. Multisite htaccess file causing segfault (Segmentation fault 11)
  83. Multisite Smtp Server
  84. Images uploaded after adding multisite do not get loaded in any domain of the multisite network
  85. Migrating from domain mapping plugin to native domain mapping
  86. WordPress API – sign-up to multiple Multisites from one single form
  87. Create multiple clones of site with different branding?
  88. Change Default site on wordpress multisite
  89. WordPress Multisite with thousands of blog
  90. Multsite Child site Auto Content
  91. Multiple devices wordpress website
  92. Cannot access network admin panel on multi site
  93. WordPress Multisite giving users access to specific Admin Pages
  94. Disable Please visit the Update Network page to update all your sites. Notice from Dashboard
  95. iis6 multisite and permissions
  96. Best way to convert two single WordPress sites into Multisite network with shared user base
  97. List all blogs a user can admin [duplicate]
  98. WordPress: How to change name of ADD-ON domain’s folder and also change/rename all references to it
  99. Enabling custom file and mime types in multisite
  100. Why does WordPress connect to site URL through internet in order to load pages
Categories multisite Tags login, multisite
How to highlight or show new to the particular posts list
Redirect logged in users from a custom post type archive page if they don’t have a specific role

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress