/// <summary> /// Validates a user based on the name and password /// </summary> /// <param name="name">Name of the user</param> /// <param name="pass">Password of the user</param> /// <returns>Returns a User if creadentials are ok, otherwise returs null</returns> public User validateUser(string name, string pass) { User user = null; String decPass; using (var conn = SqlLiteConnection(dbPath)) { try { decPass = CrypUtil.Base64Encode(pass); var result = from s in conn.Table <User>() where s.userName.Equals(name) where s.password.Equals(decPass) select s; user = result.FirstOrDefault(); } catch (Exception e) { if (e.GetType() == typeof(InvalidOperationException)) { return(null); } log.Error("Error validateUser: " + e.Message); throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError); } } return(user); }
public void encodeTest() { string expectedResult = "VGVzdFBhc3M="; string actualText = "TestPass"; string actualResult = CrypUtil.Base64Encode(actualText); Assert.AreEqual <string>(expectedResult, actualResult); }