Wrote user authentication function.