I have to implement login tokens in my Lithium (the PHP framework) based application. Two reasons:
I want to have a "remember me" function.
I also need a way of tracking logins on the server so that I can verify authenticated users on a node.js socket server like so:
- User requests a page
- Server returns a view with a session token somewhere in the HTML
- The client side JS reads the token and send it to the node.js server in an attempt to establish a connection via web sockets.
- The server receives the connect request and verifies the token sent to it with the PHP server.
- Allows or denies a connection based on the result.
So this is a two part question, and it's just to verify that I'm not being an idiot because the security on this site is of higher priority than usual.
Is this a reasonable way of creating a login token?
<?php
// String::hash() generates a sha512 (by default) hash.
String::hash(time() . $user['username']);
?>
Is the web socket authentication system I proposed sane? Can you see any problems arising or any more efficient ways of doing it?