wrote authenticate user function