Encodes a username/password pair in the format used by HTTP auth.

    The return value is a byte string in the form ``username:password``.

    .. versionadded:: 5.1
482401
def encode_username_password(
    username: Union[str, bytes], password: Union[str, bytes]
) -> bytes:
    
    if isinstance(username, unicode_type):
        username = unicodedata.normalize("NFC", username)
    if isinstance(password, unicode_type):
        password = unicodedata.normalize("NFC", password)
    return utf8(username) + b":" + utf8(password)
926356
def auth_string(self):
        '''
        
        '''

        username_token = '{username}:{token}'.format(username=self.username, token=self.token)
        b64encoded_string = b64encode(username_token)
        auth_string = 'Token {b64}'.format(b64=b64encoded_string)

        return auth_string
986118
def gen_api_key(username):
    
    salt = str(os.urandom(64)).encode('utf-8')
    return hash_password(username, salt)
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());
        }
    }
1007912
public Http auth(String username, String password) {
        return username(username).password(password);
    }
67242
def create_password_hash(password)
      encoded_password = encode_password(password)

      password_as_hex = [encoded_password].pack("v")
      password_as_string = password_as_hex.unpack("H*").first.upcase

      password_as_string[2..3] + password_as_string[0..1]
    end
1256895
def EncryptPassword(password, key):
		
		from time import time
		from array import array
		import hmac
		import sha
		import os
		import base64

		H = UcsUtils.GetShaHash

		uhash = H(','.join(str(x) for x in [`time()`, `os.getpid()`, `len(password)`, password, key]))[:16]

		k_enc, k_auth = H('enc' + key + uhash), H('auth' + key + uhash)
		n = len(password)
		passwordStream = array('L', password + '0000'[n & 3:])
		xkey = UcsUtils.Expandkey(k_enc, n + 4)

		for i in xrange(len(passwordStream)):
			passwordStream[i] = passwordStream[i] ^ xkey[i]

		ct = uhash + passwordStream.tostring()[:n]
		auth = hmac.new(ct, k_auth, sha).digest()

		encryptStr = ct + auth[:8]
		encodedStr = base64.encodestring(encryptStr)
		encryptedPassword = encodedStr.rstrip('\n')
		return encryptedPassword
632479
public static String encodeBasicAuth(final String username, final String password) {
        requireNonNull(username, "username");
        requireNonNull(password, "password");
        final String auth = username + ':' + password;
        byte[] encoded;
        try {
            encoded = Base64.getEncoder().encode(auth.getBytes(UTF_8));
        } catch (final IllegalArgumentException e) {
            throw new IllegalArgumentException("Failed to encode basic authentication token", e);
        }
        return BASIC_AUTH_PREFIX + new String(encoded, UTF_8);
    }
553756
public String getAuthString() {
        String credentials = this.username + ":" + this.password;
        try {

            String encoded = new Base64().encodeAsString(credentials.getBytes("ascii"));
            return "Basic " + encoded;

        } catch (final UnsupportedEncodingException e) {

            throw new InvalidRequestException("It must be possible to encode credentials as ascii", credentials, e);

        }
    }
953412
def encode(password, algorithm, salt, iterations):
    
    hash = hashlib.pbkdf2_hmac(digest().name, password.encode(), salt.encode(), iterations)
    encoded = base64.b64encode(hash).decode('ascii').strip()
    return "%s$%d$%s$%s" % (algorithm, iterations, salt, encoded)
341985
public String format()
    {
        if (mFormatted != null)
        {
            return mFormatted;
        }

        // userid:password
        String credentials = String.format("%s:%s",
                mUserId   == null ? "" : mUserId,
                mPassword == null ? "" : mPassword);

        // Convert the credentials into a byte array.
        byte[] credentialsBytes = getBytes(credentials);

        // Encode the byte array by Base64.
        String encoded = Base64.encodeBase64String(credentialsBytes);

        // Build the value of Authorization header.
        mFormatted = "Basic " + encoded;

        return mFormatted;
    }
409728
def _security_auth_headers(self, username, password, headers):
        
        userColonPassword = username + ":" + password
        b64UserColonPassword = base64. \
            b64encode(str_to_bytes(userColonPassword)).decode("ascii")
        headers['Authorization'] = 'Basic %s' % b64UserColonPassword
954112
def http_basic(r, username, password):
    
    username = str(username)
    password = str(password)

    auth_s = b64encode('%s:%s' % (username, password))
    r.headers['Authorization'] = ('Basic %s' % auth_s)

    return r
442474
def encode(self):
        
        # Call body before fist_line in case the query is changes.
        first_line = self.first_line()
        if self.body and self.wait_continue:
            self.headers['expect'] = '100-continue'
        headers = self.headers
        if self.unredirected_headers:
            headers = self.unredirected_headers.copy()
            headers.update(self.headers)
        buffer = [first_line.encode('ascii'), b'\r\n']
        buffer.extend((('%s: %s\r\n' % (name, value)).encode(CHARSET)
                      for name, value in headers.items()))
        buffer.append(b'\r\n')
        return b''.join(buffer)
173440
def process_auth_plain(session, encoded_auth_response)
      begin
        # extract auth id (and password)
        @auth_values = Base64.decode64(encoded_auth_response).split("\x00")
        # check for valid credentials parameters
        raise Smtpd500Exception unless @auth_values.length == 3
        # call event function to test credentials
        return_value = on_auth_event(session[:ctx], @auth_values[0], @auth_values[1], @auth_values[2])
        if return_value
          # overwrite data with returned value as authorization id
          @auth_values[0] = return_value
        end
        # save authentication information to ctx
        session[:ctx][:server][:authorization_id] = @auth_values[0].to_s.empty? ? @auth_values[1] : @auth_values[0]
        session[:ctx][:server][:authentication_id] = @auth_values[1]
        session[:ctx][:server][:authenticated] = Time.now.utc
        # response code
        return '235 OK'

      ensure
        # whatever happens in this check, reset next sequence
        session[:cmd_sequence] = :CMD_RSET
      end
    end
397859
def header_encode(header_bytes, charset='iso-8859-1'):
    
    if not header_bytes:
        return ""
    if isinstance(header_bytes, str):
        header_bytes = header_bytes.encode(charset)
    encoded = b64encode(header_bytes).decode("ascii")
    return '=?%s?b?%s?=' % (charset, encoded)
621205
def _auth(self):
        
        codec = PbufCodec()
        username = self._client._credentials.username
        password = self._client._credentials.password
        if not password:
            password = ''
        msg = codec.encode_auth(username, password)
        resp_code, _ = self._non_connect_send_recv_msg(msg)
        if resp_code == riak.pb.messages.MSG_CODE_AUTH_RESP:
            return True
        else:
            return False