Esempio 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);
            }
        }
Esempio n. 2
0
        public MUserVM Login(string username, string password, out string message)
        {
            string     encodedPassFromDB;
            bool       matchPass  = false;
            MUser      objRetUser = new MUser();
            MUserVM    objUser    = new MUserVM();
            MUserRPO   muserRPO   = new MUserRPO(imap_);
            Conditions cnd        = new Conditions();

            cnd.AddFilter(nameof(MUser.Username), Operator.Equals(username));
            cnd.AddFilter(nameof(MUser.IsActive), Operator.Equals(1));
            cnd.AddFilter(nameof(MUser.IsLocked), Operator.Equals(0));
            muserRPO.Conditions(cnd);
            //muserRPO.Where(nameof(MUser.IsActive)).Equals(1);
            //muserRPO.Where(nameof(MUser.IsLocked)).Equals(0);
            if (muserRPO.ReadOne(ref exec) && muserRPO.Result.AffectedRow > 0)
            {
                encodedPassFromDB = muserRPO.Result.Row.Password;
                matchPass         = Helpers.Crypto.ValidateKey(password, encodedPassFromDB);
                objRetUser        = matchPass ? muserRPO.Result.Row : null;
                if (matchPass)
                {
                    objUser.objUser  = objRetUser;
                    objUser.ListRole = new List <TuserRole>();
                    TUserRoleRPO objUrole = new TUserRoleRPO(imap_);
                    objUrole.Conditions(nameof(TuserRole.Username), Operator.Equals(objRetUser.Username));
                    //objUrole.Where(nameof(TUserRole.Username)).Equals(objRetUser.Username);
                    if (objUrole.ReadList(ref exec))
                    {
                        objUser.ListRole = objUrole.Result.Collection;
                    }
                    message = exec.Message;
                }
                else
                {
                    message = "Incorrect Username or Password";
                }
            }
            else
            {
                message = exec.Message;
            }

            return(objUser);
        }