Transform a username:password value into a base64 string.
515235
def transform_api_header_authorization(param, value):
    """"""
    try:
        username, password = value.split(":", 1)
    except ValueError:
        raise click.BadParameter(
            "Authorization header needs to be Authorization=username:password",
            param=param,
        )

    value = "%s:%s" % (username.strip(), password)
    value = base64.b64encode(bytes(value.encode()))
    return "Basic %s" % value.decode("utf-8")
71505
private String createAuthEncoded() {
        JsonObject ret = new JsonObject();
        putNonNull(ret, "username", username);
        putNonNull(ret, "password", password);
        putNonNull(ret, "email", email);
        putNonNull(ret, "auth", auth);
        try {
            return encodeBase64ChunkedURLSafeString(ret.toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return encodeBase64ChunkedURLSafeString(ret.toString().getBytes());
        }
    }
694239
def pwgen(length=None):
    """"""
    if length is None:
        # A random length is ok to use a weak PRNG
        length = random.choice(range(35, 45))
    alphanumeric_chars = [
        l for l in (string.ascii_letters + string.digits)
        if l not in 'l0QD1vAEIOUaeiou']
    # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
    # actual password
    random_generator = random.SystemRandom()
    random_chars = [
        random_generator.choice(alphanumeric_chars) for _ in range(length)]
    return(''.join(random_chars))
53054
def passwordLogin(self, username):
        
        self.challenge = secureRandom(16)
        self.username = username
        return {'challenge': self.challenge}
647839
def create_authentication_string(username, password):
    '''
    
    '''

    username_utf8 = username.encode('utf-8')
    userpw_utf8 = password.encode('utf-8')
    username_perc = quote(username_utf8)
    userpw_perc = quote(userpw_utf8)

    authinfostring = username_perc + ':' + userpw_perc
    authinfostring_base64 = base64.b64encode(authinfostring.encode('utf-8')).decode('utf-8')
    return authinfostring_base64
365075
function base64credentials () {
  var id = this.client.client_id
  var secret = this.client.client_secret
  var credentials = id + ':' + secret

  return Buffer.from(credentials).toString('base64')
}
294897
def password_generator(length):
    
    return ''.join(random.choice(string.ascii_lowercase + string.digits)
                   for _ in range(length))
879248
def get_password(self, service, username):
        
        assoc = self._generate_assoc(service, username)
        service = escape_for_ini(service)
        username = escape_for_ini(username)

        # load the passwords from the file
        config = configparser.RawConfigParser()
        if os.path.exists(self.file_path):
            config.read(self.file_path)

        # fetch the password
        try:
            password_base64 = config.get(service, username).encode()
            # decode with base64
            password_encrypted = decodebytes(password_base64)
            # decrypt the password with associated data
            try:
                password = self.decrypt(password_encrypted, assoc).decode(
                    'utf-8')
            except ValueError:
                # decrypt the password without associated data
                password = self.decrypt(password_encrypted).decode('utf-8')
        except (configparser.NoOptionError, configparser.NoSectionError):
            password = None
        return password
785822
def _password_digest(username, password):
    
    if not isinstance(password, basestring):
        raise TypeError("password must be an instance of basestring")
    if not isinstance(username, basestring):
        raise TypeError("username must be an instance of basestring")

    md5hash = hashlib.md5()
    md5hash.update("%s:mongo:%s" % (username.encode('utf-8'),
                                    password.encode('utf-8')))
    return unicode(md5hash.hexdigest())
1332001
function encode_password($password){
        $password="\"".$password."\"";
        $encoded="";
        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
        return ($encoded);
    }
913169
def toBase64(s):
    """"""
    if isinstance(s, str):
        s = s.encode("utf-8")
    return binascii.b2a_base64(s)[:-1]
436412
def generate_password(length=32):
    
    return ''.join(random.SystemRandom().choice(string.ascii_letters + '!@#$+.,') for _ in range(length))
1372277
def set_password(self, service, username, password):
        
        if not username:
            # https://github.com/jaraco/keyrings.alt/issues/21
            raise ValueError("Username cannot be blank.")
        if not isinstance(password, string_types):
            raise TypeError("Password should be a unicode string, not bytes.")
        assoc = self._generate_assoc(service, username)
        # encrypt the password
        password_encrypted = self.encrypt(password.encode('utf-8'), assoc)
        # encode with base64 and add line break to untangle config file
        password_base64 = '\n' + encodebytes(password_encrypted).decode()

        self._write_config_value(service, username, password_base64)
1322269
protected String encodePassword(String password)
   {
      StringBuilder result = new StringBuilder();
      if (password != null)
      {
         for (int i = 0; i < password.length(); i++)
         {
            int c = password.charAt(i);
            c ^= 0xdfaa;
            result.append(Integer.toHexString(c));
         }
      }
      return result.toString();
   }
373221
def get_auth_basic(self):
        """"""
        username = ''
        password = ''
        auth_header = self.get_header('authorization')
        if auth_header:
            m = re.search(r"^Basic\s+(\S+)$", auth_header, re.I)
            if m:
                auth_str = Base64.decode(m.group(1))
                username, password = auth_str.split(':', 1)

        return username, password
1341577
def str_encode(value, encoder='base64'):
    '''
    
    '''
    if six.PY2:
        try:
            out = value.encode(encoder)
        except LookupError:
            raise SaltInvocationError('You must specify a valid encoder')
        except AttributeError:
            raise SaltInvocationError('Value must be an encode-able string')
    else:
        if isinstance(value, six.string_types):
            value = value.encode(__salt_system_encoding__)
        if encoder == 'base64':
            try:
                out = base64.b64encode(value)
                out = out.decode(__salt_system_encoding__)
            except TypeError:
                raise SaltInvocationError('Value must be an encode-able string')
        else:
            try:
                out = value.encode(encoder)
            except LookupError:
                raise SaltInvocationError('You must specify a valid encoder')
            except AttributeError:
                raise SaltInvocationError('Value must be an encode-able string')
    return out
152798
protected void transformPassword(final UsernamePasswordCredential userPass) throws FailedLoginException, AccountNotFoundException {
        if (StringUtils.isBlank(userPass.getPassword())) {
            throw new FailedLoginException("Password is null.");
        }
        LOGGER.debug("Attempting to encode credential password via [{}] for [{}]", this.passwordEncoder.getClass().getName(), userPass.getUsername());
        val transformedPsw = this.passwordEncoder.encode(userPass.getPassword());
        if (StringUtils.isBlank(transformedPsw)) {
            throw new AccountNotFoundException("Encoded password is null.");
        }
        userPass.setPassword(transformedPsw);
    }