简体   繁体   中英

Storing user password in PHP for RESTful API authentication

I am currently in the process of designing architecture which allows my client websites to communicate with a master RESTful API secured by Basic Authentication on another server using a cross origin header.

When users register on one of the websites the form is posted to a PHP file that then creates a stream and posts the data over to the API on the master server (both servers are SSL secured).

The issue comes after this. With each request to the API I need to re-provide the users' username and password in order to successfully authenticate them through Basic Authentication.

How can I safely store the username and password of the user so that I can continue to provide the client website with access to the API whilst the user makes changes to their account?

Would it be considered secure enough to store an encrypted username and password in session variables? Users will be passing sensitive information such as a credit card number through to the master API so security is top priority.

If you really really need to store the user name and password in the SESSION . Then encrypt both the username and Password with a server-side key .

This server side key will be in a file in your server BUT NOT IN THE ROOT FOLDER , outside the root folder and you can decrypt while you are sending the credentials to the API .

So, even if your sessions are hijacked, it wont be easy to crack the credentials wothout the server side key .

May be you want to have a look at these links

Creating a secure REST API

SO - PHP Session Security

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM