What is the best way to go about generating a "token" for user authentication

  authentication, php, security, token

Let’s say I have a MySQL database with thousands of user accounts in it. These accounts contain lots of data, but for verification purposes, they each contain a username and a (hashed and salted) password. Now, when a user requests signing in, I will take a username and password from them, transfer it via WSS to a Node.js server then transfer it via HTTPS to a PHP file on another server. On that server I will look up the username in the MySQL database, and if I find an account, I will hash the password and see if it matches that username’s password. If they both match, then I want the PHP file to create a "verification token" of sorts, save it (and associate it with the account verified) and send the token back to the Node.js server. I then want the Node.js server to send that token back to the client and for the client to save that token. Now the next time the user connects to the Node.js server via WSS, I want the client to check for an existing token, and if it exists I want it to send that token via WSS to the Node.js server, the Node.js server to send that via HTTPS to a PHP file, and that PHP file to see what account that token belongs to, and complete the sign in…

So I guess my first question would be: Is this a good model? Would this be a good idea, and would this be secure, or should I do this differently?

My second question is: What would be the best way to go about generating this token? Should it be completely random? Should it be a combination of letters+numbers? Should it be a hash of some random values? How should I go about the generation of this "token"?

To clarify, I’m not asking how to build a server or make requests or transfer data or anything of that sort, I’m merely asking what is the most secure way to generate a "token" that can be used as authentication to the same degree that a username+password can be used.

Thanks in advance! I’m sorry if this is a really stupid question.

Source: Ask PHP