public HttpResponseMessage AuthenticateUser([FromBody] PasswordModel passwordModel) { try { string password = PasswordHash.MD5Hash(passwordModel.Password); var userObj = UserPL.AuthenticateUser(passwordModel.Username, password); if (userObj == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Username/Password")); } else if (userObj.ID == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Username/Password")); } else { return(Request.CreateResponse(HttpStatusCode.OK, userObj)); } } catch (Exception ex) { ErrorHandler.WriteError(ex); var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return(response); } }
public UserDetails AuthenticateUser(string key, string key_pd) { var msg = string.Empty; var user = new UserDetails(); try { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(key_pd)) { user.Response = String.Format("{0}|{1}", "Failed", "All the parameters compulsory."); } else { string password = PasswordHash.MD5Hash(key_pd); string username = key; var details = UserPL.AuthenticateUser(username, password); if (details == null) { user.Response = String.Format("{0}|{1}", "Failed", "Validation of user failed"); } else { user = details; user.Response = String.Format("{0}|{1}", "Success", "Validation of user is successful"); } } } catch (Exception ex) { user.Response = String.Format("{0}|{1}", "Failed", ex.Message); ErrorHandler.WriteError(ex); } return(user); }