public AuthenticationResult Authenticate(decimal mobileNumber, string password) { var result = new AuthenticationResult { Profile = new UserProfile() }; using (var connection = new SqlConnection(_connectionstring)) { connection.Open(); var command = new SqlCommand(string.Format("select * from users where mobilenumber = {0} and password = '******'", mobileNumber, password) , connection); var ds = new DataSet(); var adapter = new SqlDataAdapter(command); adapter.Fill(ds); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { var data = ds.Tables[0].Rows[0]; if (password == data.AsString("password") && mobileNumber == data.AsDecimal("mobilenumber")) { result.IsSuccess = true; result.Profile = GetProfile(data.AsDecimal("id")); result.Profile.UserName = string.Format("{0} {1}", data.AsString("firstname"), data.AsString("lastname")); } } } } return result; }
public JsonResult Authenticate(AuthenticationRequest request) { var result = new AuthenticationResult(); var userProfile = usersRepository.Authenticate(request.MobileNumber, request.Password); if (userProfile == null) { result.IsSuccess = false; result.ErrorMessage = "Login Failure: Either the Mobile Number or Password is Incorrect."; } else { result.IsSuccess = true; result.Profile = userProfile; } return Json(result, JsonRequestBehavior.AllowGet); }