Fix authentication

Simplified some queries (e.g. put hard-coded parameters directly into
query), fix insert for session that doesn't have a sequence.