Checks that passwords in the user files are not in clear text. If a hash
value is found for some user, it is assumed that all user passwords have
previously been hashed and no further checks are done.
175690
@Override
    public void contextInitialized(ServletContextEvent evt) {
        File usersDir = new File(SetupOptions.getBaseConfigDirectory(), "users");
        if (!usersDir.isDirectory()) {
            return;
        }
        DocumentBuilder domBuilder = null;
        try {
            domBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            LOGR.warning(e.getMessage());
            return;
        }
        DOMImplementationLS lsFactory = buildDOM3LoadAndSaveFactory();
        LSSerializer serializer = lsFactory.createLSSerializer();
        serializer.getDomConfig().setParameter(Constants.DOM_XMLDECL, Boolean.FALSE);
        serializer.getDomConfig().setParameter(Constants.DOM_FORMAT_PRETTY_PRINT, Boolean.TRUE);
        LSOutput output = lsFactory.createLSOutput();
        output.setEncoding("UTF-8");
        for (File userDir : usersDir.listFiles()) {
            File userFile = new File(userDir, "user.xml");
            if (!userFile.isFile()) {
                continue;
            }
            try {
                Document doc = domBuilder.parse(userFile);
                Node pwNode = doc.getElementsByTagName("password").item(0);
                if (null == pwNode) {
                    continue;
                }
                String password = pwNode.getTextContent();
                if (password.split(":").length == 5) {
                    break;
                }
                pwNode.setTextContent(PasswordStorage.createHash(password));
                // overwrite contents of file
                // Fortify Mod: Make sure that the output stream is closed
                // output.setByteStream(new FileOutputStream(userFile, false));
                FileOutputStream os = new FileOutputStream(userFile, false);
                output.setByteStream(os);
                serializer.write(doc, output);
                os.close();
            } catch (Exception e) {
                LOGR.info(e.getMessage());
                continue;
            }
        }
    }
1037659
private boolean isValid()
    {
        StringBuilder builder = new StringBuilder();
        for (Match match : matches)
        {
            builder.append(match.getToken());
        }

        return password.equals(builder.toString());
    }
1225750
public boolean isValid(String password) {
        if (password == null) {
            return false;
        }

        boolean length = hasMinimumLength(password, getMinimumLength());
        boolean other = true;
        switch (complexity.getPasswordPolicy()) {
            case PasswordStrength.EXCELLENT:
                boolean atLeast = atLeastThree(hasLowercaseCharacters(password), hasUppercaseCharacters(password), hasNumericCharacters(password), hasSpecialCharacters(password));
                other = hasIdenticalCharacters(password) && atLeast;
                break;
            case PasswordStrength.GOOD:
                other = atLeastThree(hasLowercaseCharacters(password), hasUppercaseCharacters(password), hasNumericCharacters(password), hasSpecialCharacters(password));
                break;
            case PasswordStrength.FAIR:
                other = allThree(hasLowercaseCharacters(password), hasUppercaseCharacters(password), hasNumericCharacters(password));
                break;
            case PasswordStrength.LOW:
            case PasswordStrength.NONE:
        }
        return length && other;
    }
76049
private boolean isValidTenantUserAccess(Tenant tenant, String userid, String password, Permission permNeeded) {
        TenantDefinition tenantDef = tenant.getDefinition();
        assert tenantDef != null;
        if (tenantDef.getUsers().size() == 0) {
            // We allow access to the default tenant when it has no users defined.
            return tenant.getName().equals(m_defaultTenantName);
        }
        UserDefinition userDef = tenantDef.getUser(userid);
        if (userDef == null || Utils.isEmpty(password)) {
            return false;   // no such user or no password given
        }
        if (userDef.getHash() != null) {
            if (!PasswordManager.checkPassword(password, userDef.getHash())) {
                return false;   // password is hashed but didn't match
            }
        } else {
            if (!password.equals(userDef.getPassword())) {
                return false;   // password is plaintext but didn't match
            }
        }
        return isValidUserAccess(userDef, permNeeded);
    }
193157
def pwned_password(password):
    
    if not isinstance(password, text_type):
        raise TypeError('Password values to check must be Unicode strings.')
    password_hash = hashlib.sha1(password.encode('utf-8')).hexdigest().upper()
    prefix, suffix = password_hash[:5], password_hash[5:]
    results = _get_pwned(prefix)
    if results is None:
        # Gracefully handle timeouts and HTTP error response codes.
        return None
    return results.get(suffix, 0)
33679
public final void clearPassword() {
        if (password != null) {
            for (int i = 0; i < password.length; i++) {
                password[i] = ' ';
            }
            password = null;
        }
    }
1160018
private static boolean isSolrSpellcheckIndexDirectoryEmpty() {

        final File path = new File(getSolrSpellcheckRfsPath());
        final File[] directories = path.listFiles(SPELLCHECKING_DIRECTORY_NAME_FILTER);

        // Each directory that has been created by Solr but hasn't been indexed yet
        // contains exactly two files. If there are more files, at least one index has
        // already been built, so return false in that case.
        if (directories != null) {
            for (final File directory : directories) {
                if (directory.list().length > 2) {
                    return false;
                }
            }
        }
        return true;
    }
1263557
public function checkPassword(): bool
    {
        if (!isset($this->regex)) {
            return true;
        }

        return filter_var($this->password, FILTER_VALIDATE_REGEXP, [
            'options' => [
                'regexp' => $this->regex
            ]
        ]);
    }
60960
@Override
    public boolean validatePassword(String cleartext, String encrypted) {
        // If local account has no password, do not allow login.
        if (encrypted == null) {
            return false;
        } else if (encrypted.startsWith(MD5_PREFIX)) {
            encrypted = encrypted.substring(5);
            return md5Encryptor.checkPassword(cleartext, encrypted);
        } else if (encrypted.startsWith(SHA256_PREFIX)) {
            encrypted = encrypted.substring(8);
            return sha256Encryptor.checkPassword(cleartext, encrypted);
        } else {
            throw new IllegalArgumentException(
                    "This portal password service is only currently capable of validating MD5 and SHA-256 passwords");
        }
    }
977997
def is_password_valid(password):
    
    pattern = re.compile(r"^.{4,75}$")
    return bool(pattern.match(password))
929851
def _checkFileExists(self):
        
        if self._fileName and not os.path.exists(self._fileName):
            msg = "File not found: {}".format(self._fileName)
            logger.error(msg)
            self.setException(IOError(msg))
            return False
        else:
            return True
498970
def clean_password(self):
        
        user_pass = self.cleaned_data.get('password')
        matches = Password.objects.filter(password=user_pass)
        if not matches:
            raise forms.ValidationError("Your password does not match.")
1196135
def check_hashes(self, filename, resource):
        
        # which hashes to calculate?
        hashes = []
        if ('md5' in self.hashes and resource.md5 is not None):
            hashes.append('md5')
        if ('sha-1' in self.hashes and resource.sha1 is not None):
            hashes.append('sha-1')
        if ('sha-256' in self.hashes and resource.sha256 is not None):
            hashes.append('sha-256')
        # calculate
        hasher = Hashes(hashes, filename)
        # check and report
        if ('md5' in hashes and resource.md5 != hasher.md5):
            self.logger.info(
                "MD5 mismatch for %s, got %s but expected %s" %
                (resource.uri, hasher.md5, resource.md5))
        if ('sha-1' in hashes and resource.sha1 != hasher.sha1):
            self.logger.info(
                "SHA-1 mismatch for %s, got %s but expected %s" %
                (resource.uri, hasher.sha1, resource.sha1))
        if ('sha-256' in hashes and resource.sha256 != hasher.sha256):
            self.logger.info(
                "SHA-256 mismatch for %s, got %s but expected %s" %
                (resource.uri, hasher.sha256, resource.sha256))
1211984
def check_files(files)
      files.each { |file| check_file(file) if file.is_a? String }
    end
786202
void checkSecurity(String password) {

        I_CmsPasswordHandler handler = OpenCms.getPasswordHandler();
        try {
            handler.validatePassword(password);
            if (handler instanceof I_CmsPasswordSecurityEvaluator) {
                SecurityLevel level = ((I_CmsPasswordSecurityEvaluator)handler).evaluatePasswordSecurity(password);
                m_pw.setErrorPassword1(null, OpenCmsTheme.SECURITY + "-" + level.name());
            } else {
                m_pw.setErrorPassword1(null, OpenCmsTheme.SECURITY_STRONG);
            }
        } catch (CmsSecurityException e) {
            m_pw.setErrorPassword1(
                new UserError(e.getLocalizedMessage(A_CmsUI.get().getLocale())),
                OpenCmsTheme.SECURITY_INVALID);
        }
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_pw.getPassword2())) {
            showPasswordMatchError(!password.equals(m_pw.getPassword2()));
        }
    }
603087
public function check()
    {
        if ($this->path[0] == '/') {
            $filename = $this->path;
        } else {
            $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
        }

        if (file_exists($filename)) {
            $isWriteable = is_writeable($filename);
        } else {
            $isWriteable = is_writeable(dirname($filename));
        }

        if (!$isWriteable) {
            if (function_exists('posix_getgroups')) {
                $userID = posix_geteuid();
                $user = posix_getpwuid($userID);

                $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
                $currentOwner = posix_getpwuid($currentOwnerID);

                $message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is "
                    . "currently owned by '$currentOwner[name]'.  ";

                if ($user['name'] == $currentOwner['name']) {
                    $message .= 'We recommend that you make the file writeable.';
                } else {
                    $groups = posix_getgroups();
                    $groupList = [];
                    foreach ($groups as $group) {
                        $groupInfo = posix_getgrgid($group);
                        if (in_array($currentOwner['name'], $groupInfo['members'])) {
                            $groupList[] = $groupInfo['name'];
                        }
                    }
                    if ($groupList) {
                        $message .= "	We recommend that you make the file group-writeable and change the group to "
                            . "one of these groups:\n - " . implode("\n - ", $groupList)
                            . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename";
                    } else {
                        $message .= "  There is no user-group that contains both the web-server user and the owner "
                            . "of this file.  Change the ownership of the file, create a new group, or temporarily "
                            . "make the file writeable by everyone during the install process.";
                    }
                }
            } else {
                $message = "The webserver user needs to be able to write to this file:\n$filename";
            }

            return [EnvironmentCheck::ERROR, $message];
        }

        return [EnvironmentCheck::OK, ''];
    }
629629
def _check_users(users):

    ''''''

    messg = ''
    valid = True

    for user, user_details in six.iteritems(users):
        if not user_details:
            valid = False
            messg += 'Please provide details for username {user}.\n'.format(user=user)
            continue
        if not (isinstance(user_details.get('level'), int) or 0 <= user_details.get('level') <= 15):
            # warn!
            messg += 'Level must be a integer between 0 and 15 for username {user}. Will assume 0.\n'.format(user=user)

    return valid, messg