Set a password for a GNTP Message

		:param string password: Null to clear password
		:param string encryptAlgo: Supports MD5, SHA1, SHA256, SHA512
353163
def set_password(self, password, encryptAlgo='MD5'):
		
		if not password:
			self.info['encryptionAlgorithmID'] = None
			self.info['keyHashAlgorithm'] = None
			return

		self.password = gntp.shim.b(password)
		self.encryptAlgo = encryptAlgo.upper()

		if not self.encryptAlgo in self.hash_algo:
			raise errors.UnsupportedError('INVALID HASH "%s"' % self.encryptAlgo)

		hashfunction = self.hash_algo.get(self.encryptAlgo)

		password = password.encode('utf8')
		seed = time.ctime().encode('utf8')
		salt = hashfunction(seed).hexdigest()
		saltHash = hashfunction(seed).digest()
		keyBasis = password + saltHash
		key = hashfunction(keyBasis).digest()
		keyHash = hashfunction(key).hexdigest()

		self.info['keyHashAlgorithmID'] = self.encryptAlgo
		self.info['keyHash'] = keyHash.upper()
		self.info['salt'] = salt.upper()
981567
public ParallelTaskBuilder setSshPassword(String password) {
        this.sshMeta.setPassword(password);
        this.sshMeta.setSshLoginType(SshLoginType.PASSWORD);
        return this;
    }
524487
public function setPassword($password = null)
    {
        if (empty($password)) {
            $passwordHash = '';
        } else {
            $passwordHash = $this->hashPassword($password);
        }

        $this->oxuser__oxpassword = new \OxidEsales\Eshop\Core\Field($passwordHash, \OxidEsales\Eshop\Core\Field::T_RAW);
        $this->oxuser__oxpasssalt = new \OxidEsales\Eshop\Core\Field('');
    }
373835
def check_password(raw_password, enc_password):
    
    algo, salt, hsh = enc_password.split('$')
    return enc_password == encrypt_password(raw_password, algorithm=algo,
                                            salt=salt)
1081601
private static String decode_password(String encoded_string, String crypto_algorithm) {
        /*
         * decoding process:
         * 
         * -- check for empty algorithm tag
         * -- convert input String to byte[] using base64 decoding
         * -- decipher byte[]
         * -- convert byte[] to String using UTF8 conversion code
         */

        StringBuilder buffer = new StringBuilder();

        if (crypto_algorithm.length() == 0) {
            // crypto algorithm is empty ... don't decode password
            buffer.append(encoded_string);
        } else {
            // decode password with specified crypto algorithm
            String decoded_string = null;
            if (encoded_string.length() > 0) {
                // convert viewable string to encrypted password byte[]
                byte[] encrypted_bytes = convert_viewable_to_bytes(encoded_string);
                logger.logp(Level.FINEST, PasswordUtil.class.getName(), "decode_password", "byte array before decoding\n" + PasswordHashGenerator.hexDump(encrypted_bytes));

                if (encrypted_bytes == null) {
                    // base64 decoding failed
                    logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_INVALID_BASE64_STRING");
                    return null;
                }

                if (encrypted_bytes.length > 0) {
                    // decrypt encrypted password byte[] with specified crypto algorithm

                    byte[] decrypted_bytes = null;

                    try {
                        decrypted_bytes = PasswordCipherUtil.decipher(encrypted_bytes, crypto_algorithm);
                    } catch (InvalidPasswordCipherException e) {
                        logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_CYPHER_EXCEPTION", e);
                        return null;
                    } catch (UnsupportedCryptoAlgorithmException e) {
                        logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_UNKNOWN_ALGORITHM_EXCEPTION", e);
                        return null;
                    }

                    if ((decrypted_bytes != null) && (decrypted_bytes.length > 0)) {
                        // convert decrypted password byte[] to string
                        decoded_string = convert_to_string(decrypted_bytes);
                    }
                }
            }

            if ((decoded_string != null) && (decoded_string.length() > 0)) {
                // append decoded string
                buffer.append(decoded_string);
            }
        }

        return buffer.toString();
    }
302983
public String encrypt64( final String clearText, final String password )
    throws PlexusCipherException
    {
        try
        {
            byte[] clearBytes = clearText.getBytes( STRING_ENCODING );
    
            byte[] salt = getSalt( SALT_SIZE );
            
            Cipher cipher = createCipher( password.getBytes( STRING_ENCODING ), salt, Cipher.ENCRYPT_MODE  );
    
            byte [] encryptedBytes = cipher.doFinal( clearBytes );
            
            int len = encryptedBytes.length;
            
            byte padLen = (byte) ( CHUNK_SIZE - (SALT_SIZE + len + 1) % CHUNK_SIZE );
            
            int totalLen = SALT_SIZE + len + padLen + 1;
            
            byte [] allEncryptedBytes = getSalt( totalLen );
            
            System.arraycopy( salt, 0, allEncryptedBytes, 0, SALT_SIZE );
            
            allEncryptedBytes[ SALT_SIZE ] = padLen;
            
            System.arraycopy( encryptedBytes, 0, allEncryptedBytes, SALT_SIZE + 1, len );
            
            byte [] encryptedTextBytes = Base64.encodeBase64( allEncryptedBytes );
            
            String encryptedText = new String( encryptedTextBytes, STRING_ENCODING );
    
            return encryptedText;
        }
        catch( Exception e)
        {
            throw new PlexusCipherException(e);
        }
    }
750857
def a_send_password(password, ctx):
    
    if password:
        ctx.ctrl.send_command(password, password=True)
        return True
    else:
        ctx.ctrl.disconnect()
        raise ConnectionAuthenticationError("Password not provided", ctx.ctrl.hostname)
1099638
private String encryptPassword(String password)
            throws AuthenticationException {
        byte[] passwordBytes = password.getBytes();

        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(passwordBytes);

            byte messageDigest[] = algorithm.digest();
            BigInteger number = new BigInteger(1, messageDigest);

            password = number.toString(16);
            if (password.length() == 31) {
                password = "0" + password;
            }
        } catch (Exception e) {
            throw new AuthenticationException(
                    "Internal password encryption failure: " + e.getMessage());
        }
        return password;
    }
807022
def setpassword(self, password):
        
        self._password = password
        if self._file_parser:
            if self._file_parser.has_header_encryption():
                self._file_parser = None
        if not self._file_parser:
            self._parse()
        else:
            self._file_parser.setpassword(self._password)
1331769
def password_set(username=None, password=None):
    
    result = keyring.set_password('supernova', username, password)

    # NOTE: keyring returns None when the storage is successful.  That's weird.
    if result is None:
        return True
    else:
        return False
375857
public static function passwordHash(string $password, string $algo = PASSWORD_BCRYPT): string
    {
        return password_hash($password, $algo);
    }
654837
public function encryptString($algo, $string, $key = null)
    {     
        if (!empty($algo) && !empty($string)) {   
            if ($key == null) {
                $ctx = hash_init($algo);
            } else {
                $ctx = hash_init($algo, HASH_HMAC, $key);
                hash_update($ctx, $string);
            }
            return hash_final($ctx);
        }
        return false;
    }
281543
public function setPasswordEncryption($passwordEncryption)
    {
        $passwordEncryption = (string) $passwordEncryption;
        if ($passwordEncryption === '') {
            throw new \InvalidArgumentException('$passwordEncryption cannot be empty');
        }

        $this->passwordEncryption = $passwordEncryption;

        return $this;
    }
1026262
public static String removeCryptoAlgorithmTag(String password) {
        if (null == password) {
            return null;
        }

        String rc = null;
        String data = password.trim();
        if (data.length() >= 2) {
            if ('{' == data.charAt(0)) {
                int end = data.indexOf('}', 1);
                if (end > 0) {
                    end++; // we want to jump past the end marker
                    if (end == data.length()) {
                        rc = EMPTY_STRING;
                    } else {
                        rc = data.substring(end).trim();
                    }
                }
            }
        }

        return rc;
    }
681375
public function setPassword($password)
    {
        if ($this->username === null) {
            throw new InvalidConfigException('用户名不能为空');
        }
        
        $this->password = md5($password . $this->username);
    }
666426
def set_password(self, password):
        
        self.password = Security.hash(password)
        self.save()
569582
def setpassword(self, pwd):
        """"""
        if pwd and not isinstance(pwd, bytes):
            raise TypeError("pwd: expected bytes, got %s" % type(pwd))
        if pwd:
            self.pwd = pwd
        else:
            self.pwd = None