Exemplo n.º 1
0
        public Enumaration.LoginStatus Authenticate(ref DataSet dsUser, string User, string txtPwd, string domainName)
        {
            dsUser = GetUserById(User);
            if (dsUser == null || dsUser.Tables[0].Rows.Count <= 0)
            {
                return(Enumaration.LoginStatus.InvalidLoginId);
            }
            else if (dsUser.Tables[0].Rows[0]["IS_ACTIVE"].ToString().Equals("0"))
            {
                return(Enumaration.LoginStatus.Inactive);
            }

            //If is system user then authenticate from db else authenticate from LDAP.
            if (dsUser.Tables[0].Rows[0][Entities.Users.AUTHENTICATION_PROVIDER] != DBNull.Value &&
                dsUser.Tables[0].Rows[0][Entities.Users.AUTHENTICATION_PROVIDER].ToString().Trim().Equals("SYS")
                )
            {
                if (Util.verifyMd5Hash(txtPwd, dsUser.Tables[0].Rows[0][Entities.Users.PASSWORD].ToString()))
                {
                    return(Enumaration.LoginStatus.Success);
                }
                else
                {
                    return(Enumaration.LoginStatus.IncorrectPassword);
                }
            }
            else if (dsUser.Tables[0].Rows[0][Entities.Users.AUTHENTICATION_PROVIDER] != DBNull.Value &&
                     dsUser.Tables[0].Rows[0][Entities.Users.AUTHENTICATION_PROVIDER].ToString().Trim().Equals("AD"))
            {
                ActiveDirectoryHelper ADHelper = new ActiveDirectoryHelper();
                Boolean authenticated          = ADHelper.Authenticate(User, txtPwd, domainName);
                if (authenticated)
                {
                    return(Enumaration.LoginStatus.Success);
                }
                else
                {
                    return(Enumaration.LoginStatus.LDAPNotConnecting);
                }
            }
            else
            {
                throw new Exception("Not a valid Authentication Provider found");
            }
        }