My opinion:
We must not store the user password on the client. The client must send the password to the server during registration / login and do not save it anywhere in the client. The request must be https , and the password must not be encrypted. We will encrypt the password later on the server side.
The server will generate a token for this user after the user has successfully logged in. token will contain the expired date on its own. We will use a token to authenticate permission with the server.
I think that every API request should provide a token, with the exception of registering / logging in / forgetting the password.
The token should be placed in the request header.
The server should allow the client a new token with the old token (possibly expired)
And the answer for "How does the server verify the token from the client?". There are many ways to do this. Below is my approach:
A token is created on the server side, which is the encrypted user info string (for example, the token expiration time, userid, role ... user) and password (stored only on the server side) using HMAC or RSA algorithms, when the user sends a token , the server can decrypt and get user info elapsed time without a request from the database.
In any case, this question is not related to the Swift tag.
source share