Define login statistics table

Also include an upgrade step to make sure the table is created in the SQL database.
Fix logging of statistics login.