Get password of correct length for this YubiHSM version.
173898
def get_password(hsm, args):
    
    expected_len = 32
    name = 'HSM password'
    if hsm.version.have_key_store_decrypt():
        expected_len = 64
        name = 'master key'

    if args.stdin:
        password = sys.stdin.readline()
        while password and password[-1] == '\n':
            password = password[:-1]
    else:
        if args.debug:
            password = raw_input('Enter %s (press enter to skip) (will be echoed) : ' % (name))
        else:
            password = getpass.getpass('Enter %s (press enter to skip) : ' % (name))

    if len(password) <= expected_len:
        password = password.decode('hex')
        if not password:
            return None
        return password
    else:
        sys.stderr.write("ERROR: Invalid HSM password (expected max %i chars, got %i)\n" % \
                              (expected_len, len(password)))
        return 1
826982
def create_LM_hashed_password_v1(passwd):
    """"""

    # if the passwd provided is already a hash, we just return the first half
    if re.match(r'^[\w]{32}:[\w]{32}$', passwd):
        return binascii.unhexlify(passwd.split(':')[0])

    # fix the password length to 14 bytes
    passwd = passwd.upper()
    lm_pw = passwd + '\0' * (14 - len(passwd))
    lm_pw = passwd[0:14]

    # do hash
    magic_str = b"KGS!@#$%"  # page 57 in [MS-NLMP]

    res = b''
    dobj = des.DES(lm_pw[0:7])
    res = res + dobj.encrypt(magic_str)

    dobj = des.DES(lm_pw[7:14])
    res = res + dobj.encrypt(magic_str)

    return res
6330
def password_length_needed(entropybits: Union[int, float], chars: str) -> int:
    """"""
    if not isinstance(entropybits, (int, float)):
        raise TypeError('entropybits can only be int or float')
    if entropybits < 0:
        raise ValueError('entropybits should be greater than 0')
    if not isinstance(chars, str):
        raise TypeError('chars can only be string')
    if not chars:
        raise ValueError("chars can't be null")

    # entropy_bits(list(characters)) = 6.554588
    entropy_c = entropy_bits(list(chars))
    return ceil(entropybits / entropy_c)
487339
def parse_args():
    
    global default_device

    parser = argparse.ArgumentParser(description = "Generate password AEAD using YubiHSM",
                                     add_help=True
                                     )
    parser.add_argument('-D', '--device',
                        dest='device',
                        default=default_device,
                        required=False,
                        help='YubiHSM device (default : "%s").' % default_device
                        )
    parser.add_argument('-v', '--verbose',
                        dest='verbose',
                        action='store_true', default=False,
                        help='Enable verbose operation.'
                        )
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true', default=False,
                        help='Enable debug operation.'
                        )
    parser.add_argument('--key-handle',
                        type=int, dest='key_handle',
                        required=True,
                        help='Key handle to use. Must have YHSM_ECB_BLOCK_ENCRYPT and/or YHSM_ECB_BLOCK_DECRYPT_CMP flag set.'
                        )
    parser.add_argument('-N', '--nonce',
                        dest='nonce',
                        required=True,
                        help='Nonce to use. 6 bytes encoded as 12 chars hex.'
                        )
    parser.add_argument('--set',
                        dest='set',
                        action='store_true', default=False,
                        help='Set password mode.'
                        )
    parser.add_argument('--validate',
                        dest='validate',
                        help='AEAD to validate.'
                        )
    parser.add_argument('--min_length',
                        type=int, dest='min_len',
                        required=False, default=20,
                        help='Minimum length to pad passwords to (default: 20).'
                        )

    args = parser.parse_args()

    if args.set and args.validate:
        sys.stderr.write("Arguments --set and --validate are mutually exclusive.\n")
        sys.exit(1)
    if not args.set and not args.validate:
        sys.stderr.write("Either --set or --validate must be specified.\n")
        sys.exit(1)

    return args
49346
def hash_password(password):
    
    if use_double_hash():
        password = get_hmac(password).decode('ascii')

    return _pwd_context.hash(
        password,
        **config_value('PASSWORD_HASH_OPTIONS', default={}).get(
            _security.password_hash, {})
    )
436412
def generate_password(length=32):
    
    return ''.join(random.SystemRandom().choice(string.ascii_letters + '!@#$+.,') for _ in range(length))
974364
def check_password(cls, instance, raw_password, enable_hash_migration=True):
        
        verified, replacement_hash = instance.passwordmanager.verify_and_update(
            raw_password, instance.user_password
        )
        if enable_hash_migration and replacement_hash:
            if six.PY2:
                instance.user_password = replacement_hash.decode("utf8")
            else:
                instance.user_password = replacement_hash
        return verified
196425
protected function getAdjustedKeyLength()
	{
		return $this->length - intval(strlen($this->prefix) + strlen($this->suffix));
	}
239257
def get_user_data_triplet(username, password):
    """"""
    context = SRPContext(username, password)
    username, password_verifier, salt = context.get_user_data_triplet(base64=True)

    click.secho('Username: %s' % username)
    click.secho('Password verifier: %s' % password_verifier)
    click.secho('Salt: %s' % salt)
765446
def password(rest):
	
	charsets = [
		string.ascii_lowercase,
		string.ascii_uppercase,
		string.digits,
		string.punctuation,
	]
	passwd = []

	try:
		length = rest.strip() or 12
		length = int(length)
	except ValueError:
		return 'need an integer password length!'

	for i in range(length):
		passwd.append(random.choice(''.join(charsets)))

	if length >= len(charsets):
		# Ensure we have at least one character from each charset
		replacement_indices = random.sample(range(length), len(charsets))
		for i, charset in zip(replacement_indices, charsets):
			passwd[i] = random.choice(charset)

	return ''.join(passwd)
251907
def password_hash(password, password_salt=None):
    """"""
    password_salt = password_salt or oz.settings["session_salt"]
    salted_password = password_salt + password
    return "sha256!%s" % hashlib.sha256(salted_password.encode("utf-8")).hexdigest()
51663
def _generate_password():
    
    uuid_str = six.text_type(uuid.uuid4()).encode("UTF-8")
    return hashlib.sha1(uuid_str).hexdigest()
782793
def __get_password(self, description='',
                       confirm=False, clear=False, username='glances'):
        
        from glances.password import GlancesPassword
        password = GlancesPassword(username=username)
        return password.get_password(description, confirm, clear)
1118846
def PASSWORD_MIN_LENGTH(self):
        
        from django.conf import settings
        ret = None
        if not settings.AUTH_PASSWORD_VALIDATORS:
            ret = self._setting("PASSWORD_MIN_LENGTH", 6)
        return ret
679525
def get_user_data_triplet(self, base64=False):
        
        salt = self.generate_salt()
        verifier = self.get_common_password_verifier(self.get_common_password_hash(salt))

        verifier = value_encode(verifier, base64)
        salt = value_encode(salt, base64)

        return self._user, verifier, salt
740411
public function getBlowfishEncryptedValue($plaintext, $length, $password): string
    {
        if (mb_strlen($password) <= 0) {
            $password = ' ';
        }
        if (mb_strlen($plaintext) != $length) {
            throw new BlowfishException('Length mismatch. The parameter len differs from actual length.');
        }

        $plaintext = $this->expand($plaintext);
        $this->bfSetKey($password);

        return bin2hex($this->encrypt($plaintext));
    }
972245
def check_password(self, hashed_password, plain_password):
        
        salt, encrypted_password = hashed_password.split('$')
        re_encrypted_password = self.get_hash(salt, plain_password)
        return encrypted_password == re_encrypted_password