public bool IsValidUser(string userName, string password) { try { if (!DB.IsNotNullOrEmpty()) { return(false); } SEC_USER_MASTER login = (from o in DB.SEC_USER_MASTER where o.USER_NAME == userName && (o.DELETE_FLAG == false || o.DELETE_FLAG == null) select o).SingleOrDefault <SEC_USER_MASTER>(); if (login.IsNotNullOrEmpty()) { return(pwdManager.IsPasswordMatch(password, login.SALT.ToArray(), login.PASSWORD.ToArray())); } else { return(false); } } catch (Exception ex) { throw ex.LogException(); } }
public bool CheckIsAdminAvailable() { //Keep the record when delete the user and maintain delete flag - 17/12/2015 SEC_USER_MASTER users = (from o in DB.SEC_USER_MASTER where o.IS_ADMIN == true && (o.DELETE_FLAG == false || o.DELETE_FLAG == null) select o).FirstOrDefault <SEC_USER_MASTER>(); try { if (users != null) { return(true); } else { return(false); } } catch (Exception ex) { ex.LogException(); return(false); } }
public bool GetisAdmin(string userName) { bool returnValue = false; try { if (DB.IsNotNullOrEmpty()) { SEC_USER_MASTER userMaster = (from row in DB.SEC_USER_MASTER where row.USER_NAME == userName && (row.DELETE_FLAG == false || row.DELETE_FLAG == null) select row).FirstOrDefault(); if (userMaster.IsNotNullOrEmpty()) { returnValue = userMaster.IS_ADMIN.ToBooleanAsString(); } } } catch (Exception ex) { throw ex.LogException(); } return(returnValue); }
public bool UpdateSecurityUsers(SecurityUsersModel user) { user.Status = ""; try { if (user.Mode == "I") { bool insert = true; //Keep the record when delete the user and maintain delete flag - 17/12/2015 SEC_USER_MASTER secUsers = (from o in DB.SEC_USER_MASTER where o.USER_NAME == user.UserName && (o.DELETE_FLAG == false || o.DELETE_FLAG == null) select o).FirstOrDefault <SEC_USER_MASTER>(); try { if (secUsers != null) { secUsers = null; user.Status = PDMsg.AlreadyExists("User"); return(false); } secUsers = new SEC_USER_MASTER(); secUsers = (from o in DB.SEC_USER_MASTER where o.USER_NAME == user.UserName && (o.DELETE_FLAG == true) select o).FirstOrDefault <SEC_USER_MASTER>(); if (secUsers != null) { insert = false; secUsers.DELETE_FLAG = false; } else { secUsers = new SEC_USER_MASTER(); } secUsers.USER_NAME = user.UserName; secUsers.FULL_NAME = user.FullName; secUsers.DESIGNATION = user.Designation; secUsers.IS_ADMIN = user.IsAdmin; byte[] salt; secUsers.PASSWORD = pwdManager.GeneratePasswordHash(user.Password, out salt); secUsers.SALT = salt; secUsers.FORCE_PASSWORD = false; secUsers.ENTERED_BY = userInformation.UserName; secUsers.ENTERED_DATE = userInformation.Dal.ServerDateTime; if (insert == true) { secUsers.ROWID = Guid.NewGuid(); DB.SEC_USER_MASTER.InsertOnSubmit(secUsers); } // AssignRolesForUser(user.UserName); DB.SubmitChanges(); secUsers = null; user.Status = PDMsg.SavedSuccessfully; return(true); } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); user.Status = PDMsg.SavedSuccessfully; return(true); } catch (Exception ex) { ex.LogException(); DB.SEC_USER_MASTER.DeleteOnSubmit(secUsers); } } else if (user.Mode == "U") { SEC_USER_MASTER users = (from o in DB.SEC_USER_MASTER where o.USER_NAME == user.UserName && (o.DELETE_FLAG == false || o.DELETE_FLAG == null) select o).FirstOrDefault <SEC_USER_MASTER>(); try { if (users != null) { users.USER_NAME = user.UserName; users.FULL_NAME = user.FullName; users.DESIGNATION = user.Designation; if (user.Password != "!@#$%^&*()") { byte[] salt; users.PASSWORD = pwdManager.GeneratePasswordHash(user.Password, out salt); users.SALT = salt; users.FORCE_PASSWORD = false; } users.IS_ADMIN = user.IsAdmin; users.UPDATED_BY = userInformation.UserName; users.UPDATED_DATE = userInformation.Dal.ServerDateTime; DB.SubmitChanges(); users = null; user.Status = PDMsg.UpdatedSuccessfully; return(true); } } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); user.Status = PDMsg.UpdatedSuccessfully; return(true); } catch (Exception ex) { ex.LogException(); DB.SEC_USER_MASTER.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, users); } } else if (user.Mode == "D") { SEC_USER_MASTER users = (from o in DB.SEC_USER_MASTER where o.USER_NAME == user.UserName select o).FirstOrDefault <SEC_USER_MASTER>(); if (users != null) { //Keep the record when delete the user and maintain delete flag - 17/12/2015 users.DELETE_FLAG = true; users.UPDATED_BY = userInformation.UserName; users.UPDATED_DATE = DateTime.Now; //DB.SEC_USER_MASTER.DeleteOnSubmit(users); DB.SubmitChanges(); users = null; user.Status = PDMsg.DeletedSuccessfully; List <SEC_USER_ROLES> lstsecuserroles = (from role in DB.SEC_USER_ROLES where role.USER_NAME.ToUpper().Trim() == user.UserName.ToUpper().Trim() select role).ToList <SEC_USER_ROLES>(); DB.SEC_USER_ROLES.DeleteAllOnSubmit(lstsecuserroles); DB.SubmitChanges(); return(true); } else if (users == null) { user.Status = PDMsg.DoesNotExists("User"); return(true); } } } catch (Exception ex) { throw ex.LogException(); } return(true); }