Ejemplo n.º 1
0
        public bool LockUserAccount(LoginInfo login, PasswordPolicy passwordpolicy) //if incorect only
        {
            var isLocked                        = false;
            IManagerCredential crd              = new ManagerCredential();
            ILayoutManager     layoutManager    = new LayoutManager();
            IReviewCredential  ReviewCredential = new ReviewCredential();
            Guid tenantId                       = layoutManager.GetTenantId(InfoType.Tenant, login.TenantCode);

            CredentialInfo usercredentialinfo = UserCredentailInfo(login);

            if (passwordpolicy.LockoutAttempt.Value != null)
            {
                int?userpermissablelockoutAttemptcount = 1;
                if (usercredentialinfo.InvalidAttemptCount == null || usercredentialinfo.InvalidAttemptCount == 0)
                {
                    usercredentialinfo.InvalidAttemptCount = 1;
                }
                userpermissablelockoutAttemptcount = Convert.ToInt32(passwordpolicy.LockoutAttempt.Value);
                if (usercredentialinfo.InvalidAttemptCount >= userpermissablelockoutAttemptcount)
                {//lock the user
                    IManagerCredential managecredential = new ManagerCredential();
                    managecredential.UpdateLockedStatus(tenantId, usercredentialinfo.CredentialId, true, usercredentialinfo.InvalidAttemptCount, DateTime.UtcNow);
                    isLocked = true;
                }
                else //invalid attempt count increses
                {
                    IManagerCredential managecredential = new ManagerCredential();
                    managecredential.UpdateLockedStatus(tenantId, usercredentialinfo.CredentialId, false, usercredentialinfo.InvalidAttemptCount + 1, null);
                }
            }
            return(isLocked);
        }
Ejemplo n.º 2
0
        public bool CheckIfLocked(LoginInfo login, PasswordPolicy passwordpolicy)
        {
            CredentialInfo usercredentialinfo = UserCredentailInfo(login);

            if (passwordpolicy.LockoutDuration.Value == null)
            {
                return(false);
            }
            if (usercredentialinfo.IsLocked)
            {
                //user was locked down now as time is over he is locked out
                if (DateTime.UtcNow > usercredentialinfo.LockedOn.AddMinutes(Convert.ToInt32(passwordpolicy.LockoutDuration.Value)))
                {
                    IManagerCredential managecredential = new ManagerCredential();
                    IManagerCredential crd              = new ManagerCredential();
                    ILayoutManager     layoutManager    = new LayoutManager();
                    IReviewCredential  ReviewCredential = new ReviewCredential();
                    Guid tenantId = layoutManager.GetTenantId(InfoType.Tenant, login.TenantCode);
                    var  userId   = crd.GetUserName(tenantId, login.UserName);
                    managecredential.UpdateLockedStatus(tenantId, usercredentialinfo.CredentialId, false, 0, null);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }