Added generic database code. Still a WIP, the protected database does not work yet.