Returns {@link UsernamePasswordToken} which holds a username and a password.
13523
private UsernamePasswordToken usernamePassword(ServiceRequestContext ctx, AggregatedHttpMessage req) {
        // check the Basic HTTP authentication first (https://tools.ietf.org/html/rfc7617)
        final BasicToken basicToken = AuthTokenExtractors.BASIC.apply(req.headers());
        if (basicToken != null) {
            return new UsernamePasswordToken(basicToken.username(), basicToken.password());
        }

        final MediaType mediaType = req.headers().contentType();
        if (mediaType != MediaType.FORM_DATA) {
            return throwResponse(ctx, HttpStatus.BAD_REQUEST,
                                 "The content type of a login request must be '%s'.", MediaType.FORM_DATA);
        }

        final Map<String, List<String>> parameters = new QueryStringDecoder(req.contentUtf8(),
                                                                            false).parameters();
        // assume that the grant_type is "password"
        final List<String> usernames = parameters.get("username");
        final List<String> passwords = parameters.get("password");
        if (usernames != null && passwords != null) {
            final String username = usernames.get(0);
            final String password = passwords.get(0);
            return new UsernamePasswordToken(loginNameNormalizer.apply(username), password);
        }

        return throwResponse(ctx, HttpStatus.BAD_REQUEST,
                             "A login request must contain username and password.");
    }
1334561
def GetSecurityToken(self, username, password):
        
        url = 'https://login.microsoftonline.com/extSTS.srf'
        body = """
                <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
                  xmlns:a="http://www.w3.org/2005/08/addressing"
                  xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
              <s:Header>
                <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
                <a:ReplyTo>
                  <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
                </a:ReplyTo>
                <a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
                <o:Security s:mustUnderstand="1"
                   xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                  <o:UsernameToken>
                    <o:Username>%s</o:Username>
                    <o:Password>%s</o:Password>
                  </o:UsernameToken>
                </o:Security>
              </s:Header>
              <s:Body>
                <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
                  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
                    <a:EndpointReference>
                      <a:Address>%s</a:Address>
                    </a:EndpointReference>
                  </wsp:AppliesTo>
                  <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
                  <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
                  <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
                </t:RequestSecurityToken>
              </s:Body>
            </s:Envelope>""" % (username, password, self.share_point_site)
        headers = {'accept': 'application/json;odata=verbose'}

        response = requests.post(url, body, headers=headers)

        xmldoc = etree.fromstring(response.content)

        token = xmldoc.find(
            './/{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}BinarySecurityToken'
        )
        if token is not None:
            return token.text
        else:
            raise Exception('Check username/password and rootsite')
775319
private String getPasswordOnRecord(final String username) throws IOException {
        try (val stream = Files.lines(fileName.getFile().toPath())) {
            return stream.map(line -> line.split(this.separator))
                .filter(lineFields -> {
                    val userOnRecord = lineFields[0];
                    return username.equals(userOnRecord);
                })
                .map(lineFields -> lineFields[1])
                .findFirst()
                .orElse(null);
        }
    }
331693
private String getSimpleUsername(String username) {
        int lastSlash = username.lastIndexOf('\\');
        if (lastSlash > -1) {
            username = username.substring(lastSlash + 1);
        }

        return username;
    }
560882
public static @Nullable @CheckForNull String getCurrentUsername() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null) {
      return null;
    }
    return getUsername(authentication);
  }
121936
public Principal authenticate(String username, char password[]) 
    throws NamingException
	{
		DirContext ctx = null;
		try
		{
			String userDN = toDN(username);
			ctx = initContext(userDN, password);

			return new X500Principal(userDN);
		}
		finally
		{
			if(ctx != null)
				try{ ctx.close(); } catch(Exception e){e.printStackTrace();}
		}
	}
354540
public String findUsername( String token ) {
		return token == null ? null : this.tokenToUsername.get( token );
	}
116304
public Authentication getAuthentication() {
        String username = getValueModel(LoginDetails.PROPERTY_USERNAME, String.class).getValue();
        String password = getValueModel(LoginDetails.PROPERTY_PASSWORD, String.class).getValue();
        return new UsernamePasswordAuthenticationToken( username, password );
    }
366965
public Token<DelegationTokenIdentifier> selectTokenFromFsOwner() throws IOException {
    return lookupToken(user.getCredentials(), service, tokenBinding.getKind());
  }
769129
public static  UUID getOrCreateUserToken() {
        UUID userToken;
        if (Request.getPerThreadRequestData().getRequestId() != null) {
            try {
                userToken = UUID.fromString(Request.getPerThreadRequestData().getRequestId());
            } catch (final IllegalArgumentException ignored) {
                userToken = UUIDs.randomUUID();
            }
        } else {
            userToken = UUIDs.randomUUID();
        }
        return userToken;
    }
1042216
protected Account authenticate(String username, String password) {
        StandardCredentials authenticationToken = new StandardCredentials(username, password);
        Account account = securityManager.authenticate(authenticationToken);
        return account;
    }
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);
    }
300661
public static CallbackHandler forNameAndPassword(String name, String password) {
    return FixedCallbackHandler.forNameAndPassword(name, password.toCharArray());
  }
780048
public TokenResult prepareLogin(String username) throws Exception {
    username = encode(username);
    Api apiResult = null;
    TokenResult token = new TokenResult();
    token.tokenName = "lgtoken";
    token.tokenMode = TokenMode.token1_19;
    // see https://github.com/WolfgangFahl/Mediawiki-Japi/issues/31
    if (this.isVersion128()) {
      apiResult = this.getQueryResult("&meta=tokens&type=login");
      super.handleError(apiResult);
      token.token = apiResult.getQuery().getTokens().getLogintoken();
    } else {
      apiResult = getActionResult("login", "&lgname=" + username, null, null);
      super.handleError(apiResult);
      Login login = apiResult.getLogin();
      token.token = login.getToken();
    }
    return token;
  }
305569
public String getToken() {
        String id = null == answer ? text : answer;
        return Act.app().crypto().generateToken(id);
    }
452259
private static String encodeAuthPlain(String username, char[] password) {
        // PLAIN mechanism encoding - NUL + username + NUL + password
        int size = username.length() + password.length + 2;
        ByteBuffer buffer = ByteBuffer.allocate(size);
        buffer.put((byte)0);
        buffer.put(username.getBytes());
        buffer.put((byte)0);
        buffer.put(new String(password).getBytes());
        
        buffer.flip();
        
        // Nulling out the password for security. 
        Arrays.fill(password, '\0');

        int len = buffer.remaining();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++)
        {
            builder.append((char)(buffer.get() & 0xff)); 

        }
        String s = builder.toString();
        return s;

    }
284380
private String getUserPassword(Object[] args) throws AuthException {
		if (args == null)
			throw new AuthException("auth error: args is null");
		if ((userPasswordPair == null) || userPasswordPair.equals("")) {
			try {
				StringBuilder sb = new StringBuilder();
				if ((args[0] != null) && (args[1] != null)) {
					sb.append(args[0]);
					sb.append(":");
					sb.append(args[1]);
					userPasswordPair = sb.toString();
				}
			} catch (Exception e) {
				throw new AuthException("auth error: args is null");
			}
		}
		Debug.logVerbose("[JdonFramework] url param is" + userPasswordPair, module);
		return userPasswordPair;
	}