Exemplo n.º 1
0
        public string LockAccount(string username, string password)
        {
            MUserRPO muserRPO = new MUserRPO(imap_);

            muserRPO.Conditions(nameof(MUser.Username), Operator.Equals(username));
            if (muserRPO.ReadOne(ref exec) && muserRPO.Result.AffectedRow > 0)
            {
                string encryptedPass = muserRPO.Result.Row.Password;
                if (Helpers.Crypto.ValidateKey(password, encryptedPass))
                {
                    muserRPO.Result.Row.IsLocked = true;
                    if (muserRPO.Update(muserRPO.Result.Row, ref exec))
                    {
                        return("");
                    }
                    else
                    {
                        return(exec.Message);
                    }
                }
                else
                {
                    return("Incorrect Username or Password");
                }
            }
            else
            {
                return(exec.Message);
            }
        }
Exemplo n.º 2
0
        private string AddOrUpdateUser(bool isUpdate, MUserVM objMuservm, string ConfirmationPassword = "")
        {
            MUserRPO muserRPO  = new MUserRPO(imap_);
            MUser    objMuser  = objMuservm.objUser;
            string   message   = "";
            bool     validPass =
                objMuser.Password.Any(c => char.IsLetter(c)) &&
                objMuser.Password.Any(c => char.IsDigit(c));

            message   = validPass ? "" : "Password must contain at least one letter and one numeric digit";
            validPass = objMuser.Password == ConfirmationPassword;
            message   = validPass ? "" : "Password didn't match";

            if (validPass)
            {
                objMuser.Password = Helpers.Crypto.EncryptPassword(objMuser.Password);
                if (objMuser.Password == "")
                {
                    //todo log
                    return("Error Encrypt");
                }
                muserRPO.BeginTrans();
                if (isUpdate)
                {
                    muserRPO.Conditions(nameof(objMuser.IsActive), Operator.Equals("true"));
                    muserRPO.Update(objMuser, ref exec);
                    AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec);
                }
                else
                {
                    muserRPO.Conditions(nameof(objMuser.Username), Operator.Equals(objMuser.Username));
                    if (muserRPO.ReadList(ref exec))
                    {
                        if (muserRPO.Result.AffectedRow > 0)
                        {
                            message = "username already Exist!";
                        }
                        else
                        {
                            muserRPO.Insert(objMuser, ref exec);
                            AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec);
                        }
                    }
                }
                message = exec.Message;
                muserRPO.EndTrans(exec);
            }
            return(message);
        }