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

Login and register by API

Q1. How can we do this login event? Can we login via API or do we need something different? I’m asking because I’ve seen ways to log in with a cookie.

The WP REST API provides no session management functionality. There is no way to login, register, or logout via the REST API.

If it did, the registration endpoint in your question would be unnecessary.

Plugins might exist that provide session management, but doing this will require 100% custom code.

If it helps, this is the automatic API discovery process for the REST API that reveals the authentication methods it exposes:

https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#authentication-discovery

You may find with 3rd party authentication plugins that the ability to login via the API and create new authentication sessions purely via the API might be possible.

Q2. When it gets Ok result from API, it will return to WordPress site and log in. How can we make this turn?

You would need to create an entirely new endpoint to do this. Software such as Softaculous has an advantage the REST API does not because it can reach behind the scenes and do things directly to the database, run PHP scripts directly with priviledged access, or WP CLI commands such as wp user create etc and do things that can’t normally be done.

A common method on enterprise hosting is to do this via a WP CLI command using internal mechanisms that aren’t reachable via a browser or the open web, such as queued tasks or internal proprietary cron jobs. Others use custom REST API endpoints that create temporary users and then set up credentials and custom filters to bypass what the site normally does ( you would not want to do this as it has major security implications and is not scalable, these systems are built with a lone hosting support/maintenance agent in mind, not for regular use ).

These usually create temporary back doors that self-close, with mechanisms that rely on temporary tokens etc


Note that if we ignore all of this, the code in the question is insecure:

  • there is no rate limiting
  • it does not check if a user already exists
    • but it does return the error object, allowing an attacker to fire of repeated requests for usernames to see which ones generate user already exists errors
    • this also works for emails!!
  • although emails are sanitised, there is nothing checking that they are emails, and the endpoint will happily accept "I'm not an email" and pass it to $email
  • the endpoint bypasses the validation/verification step to confirm the user does indeed own that email. Anybody can sign up with anybody’s email, I could sign up with your email! And there’s nothing anybody could do about it. This has major legal and regulatory consequences, you should consult a lawyer with expertise in this area before continuing.
  • There are no protections for password strength and integrity in the API, this endpoint bypasses those entirely. . would be a valid password.
    • it may even be possible to use a blank password which would make it impossible for the user to login

I suspect you’ve used this answer on Stack Overflow to create the endpoint, which has its own issues, but then removed half of the protections it uses such as username_exits etc:

https://stackoverflow.com/a/50105811/57482

Related Posts:

  1. What would be the best way to implement Magic Link logins in WordPress?
  2. Best option to implement external register/login to WP from self-made API
  3. Set logged in user based on API response
  4. How to use WordPress REST API to login a user with dart/flutter?
  5. Can I programmatically login a user without a password?
  6. SSO / authentication integration with external ‘directory service’
  7. What is $interim_login?
  8. Adding extra authentication field in login page
  9. What exactly is ReAuth?
  10. Login members using web services
  11. Disable WordPress 3.6 idle logout / login modal window / session expiration
  12. How to pass users back and forth using session data?
  13. how to authenticate for the REST API from a plugin and from command line
  14. How to check WordPress website username and password is correct
  15. Need to execute a cron job
  16. How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
  17. how to update current logged user username
  18. Validate Custom Login field
  19. WordPress REST API “rest_authentication_errors” doesn’t work external queries?
  20. Calling wp_signon doesn’t log the user in
  21. How to implement Google reCaptcha without installing a plugin?
  22. Custom Connect to Facebook, problem logging in/logging out
  23. Is it possible a one click user registration with Facebook or Twitter (or other Social Networks)?
  24. Remote REST request to check login status
  25. Are there ways of logging in that bypass wp-login.php altogether?
  26. How to display username and password after registration
  27. How to save generated JWT token to cookies on login?
  28. How to set JWT token with PHP on successful login?
  29. Calling an API to do authentication / user login
  30. Two factor authentication
  31. WordPress Login Customization for External Authentication
  32. How to generate “WP_Error” Object for user login?
  33. WordPress HTTP API NTLM Authentication
  34. Allow Access to Home Page and Login Screen but Nothing Else (unless logged in)
  35. How to authenticate a user with an external webservice
  36. Where is the php file, that does the checks for login information?
  37. I want login using email not username wordpress front end
  38. Reloading page with a query string upon login for admins
  39. WordPress authentication using custom php?
  40. authenticate user without redirecting
  41. Get WordPress login functions without printing anything
  42. Multiple issues with Ajax login function due to browsers and cookies
  43. Is there a way to call via javascript if a user is logged-in on a static html file?
  44. Secure WordPress API, how?
  45. register/login api
  46. How to post frontend login form to a different authentication script from wp-login?
  47. Custom user roles are unable to login
  48. Using WordPress login for a non word-press website
  49. The same session information for peer users on two different WordPress servers
  50. How the wordpress login and signup in react native app
  51. Extend Cookie with auth_cookie_expiration not working
  52. How to use google api for wordpress login
  53. Can we start session from another php site to wordpress blog site?
  54. Opening protected page with cookie?
  55. Handle POST request sent from an external site for login?
  56. External Authentication
  57. What is an Endpoint?
  58. In Django, how do I know the currently logged-in user?
  59. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  60. Is there any way to rename or hide wp-login.php?
  61. How to login with email only no username?
  62. How can I redirect user after entering wrong password?
  63. How to: Make JWT-authenticated requests to the WordPress API
  64. How to use OAuth authentication with REST API via CURL commands?
  65. WordPress Rest API custom endpoint optional param
  66. Increase of failed login attempts, brute force attacks? [closed]
  67. Using the Rewrite API to Construct a RESTful URL
  68. Login page ERROR: Cookies are blocked due to unexpected output
  69. Separate registration and login for different roles
  70. Preventing session timeout
  71. Create API for single sign-on with 3rd party site
  72. How reduce wordpress login session timeout time?
  73. How to prefill WordPress registration with social details
  74. Check for correct username on custom login form
  75. How to Change the Default Home Page for the WordPress Dashboard?
  76. Disallow user from editing their own profile information
  77. I can’t access my site via wp-admin
  78. ‘Password field is empty’ error when using autofill in Chrome
  79. Removing username from the ‘wordpress_logged_in’ cookie
  80. How to show ‘login error’ and ‘lost password’ on my template page?
  81. Query WP REST API v2 by multiple meta keys
  82. How do I require authorization / login to view a specific set of posts / pages?
  83. Custom login form
  84. How to prefill the username/password fields on the login page
  85. wp_signon returns user, but the user is not logged in
  86. Set up WP Authentication from External API
  87. How do I cache (core) API requests?
  88. WP REST API only returning partial list of users
  89. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  90. Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
  91. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  92. wp_signon() does not authenticate user guidance needed
  93. What are the differences between wp_users and wp_usermeta tables?
  94. WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
  95. WordPress auto login after registration not working
  96. Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
  97. Make my wordpress blog remember my login “forever”
  98. How to check in timber if user is loggedin?
  99. WordPress REST API – Permission Callbacks
  100. How do I change the language of only the login page?
Categories login Tags api, authentication, login, rest-api
CCF7 Field numbuer prefilled after Click event
How to update the input[type=number] quantity field using custom buttons?

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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