Implementing function to authenticate with database.