PasswordCallback clearPassword - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PasswordCallback clearPassword method.

This code example shows how to use the following methods:clearPassword, getPassword
        if (callbackHandler == null) {
            throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
        } 
 
        NameCallback nc = new NameCallback("User name: ", "guest");
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        Callback[] callbacks = { nc, pc };
        String username = null;
        String password = null;
        try { 
            callbackHandler.handle(callbacks);
            username = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                pc.clearPassword();
                password = new String(tmpPassword);
            } 
        } catch (IOException e) {
            LoginException le = new LoginException("Failed to get username/password");
            le.initCause(e);
8
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
        if (callbackHandler == null) {
            throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
        } 
 
        NameCallback nc = new NameCallback("User name: ", "guest");
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        Callback[] callbacks = { nc, pc };
 
        try { 
            callbackHandler.handle(callbacks);
            username = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                pc.clearPassword();
                password = new String(tmpPassword);
            } 
        } catch (IOException e) {
            LoginException le = new LoginException("Failed to get username/password");
            le.initCause(e);
            throw le;
8
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException {
 
        NameCallback nameCallback = new NameCallback("Name : ");
        PasswordCallback passwordCallback = new PasswordCallback("Password : ", false);
        try { 
            callbackHandler.handle(new Callback[]{nameCallback, passwordCallback});
            String username = nameCallback.getName();
            String password = new String(passwordCallback.getPassword());
            nameCallback.setName("");
            passwordCallback.clearPassword();
            Customer customer = customerService.findCustomer(username, password);
 
            if (customer == null) {
                throw new LoginException("Authentication failed");
            } 
 
            return true; 
        } catch (Exception e) {
6
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException {
        loginSucceeded = true;
        if (credentialsInvalidate) {
            PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
            try { 
                 callbackHandler.handle(new Callback[]{passwordCallback});
                 if (passwordCallback.getPassword() != null) {
                     if (debug) {
                        LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); 
                     } 
                     loginSucceeded = false;
                     passwordCallback.clearPassword();
                 }; 
             } catch (IOException ioe) {
             } catch (UnsupportedCallbackException uce) {
             } 
        } 
        if (debug) {
6
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword, getPrompt, isEchoOn, setPassword
public class PasswordCallbackTest extends TestCase {
 
    PasswordCallback pc;
 
    public final void testPasswordCallback() { 
        pc = new PasswordCallback("prompt", true);
        assertEquals("prompt", pc.getPrompt());
        assertTrue(pc.isEchoOn());
        pc.setPassword(null);
        pc.clearPassword();
        assertNull(pc.getPassword());
        char[] pwd = {'a','b','c'};
        pc.setPassword(pwd);
        assertEquals(new String(pwd), new String(pc.getPassword()));
        pc.clearPassword();
        assertEquals(pwd.length, pc.getPassword().length);
        assertFalse(new String(pwd).equals(pc.getPassword()));
        char[] p = new char[5];
        pc.setPassword(p);
        pc.clearPassword();

7
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException { 
        loginSucceeded = true;
        if (credentialsInvalidate) {
            PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
            try { 
                 callbackHandler.handle(new Callback[]{passwordCallback});
                 if (passwordCallback.getPassword() != null) {
                     if (debug) {
                        LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); 
                     } 
                     loginSucceeded = false;
                     passwordCallback.clearPassword();
                 }; 
             } catch (IOException ioe) {
             } catch (UnsupportedCallbackException uce) {
             } 
        } 
        if (debug) {
7
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
This code example shows how to use the following methods:clearPassword, getPassword
        this.callbackHandler = callbackHandler;
        this.sharedState = sharedState;
    } 
 
    protected String[] retrieveLogin() throws LoginException {
        PasswordCallback pc = new PasswordCallback("Password: ", false);
        NameCallback nc = new NameCallback("Username: ", "guest");
        Callback[] callbacks = { nc, pc };
        try { 
            String[] login = new String[2];
            callbackHandler.handle(callbacks);
            login[0] = nc.getName();
            char[] tmpPassword = pc.getPassword();
            if (tmpPassword != null) {
                login[1] = new String(tmpPassword);
            } 
            pc.clearPassword();
            return login;
        } catch (IOException ioe) {
            throw new LoginException(ioe.toString());

6
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
     *  @throws LoginException on error 
     */ 
    private String[] getUserPassword() throws LoginException
    { 
        final NameCallback name = new NameCallback("User Name:");
        final PasswordCallback password = new PasswordCallback("Password :", false);
        try 
        { 
            callbackHandler.handle(new Callback[] { name, password });
        } 
        catch (Throwable ex)
        { 
            ex.printStackTrace();
            throw new LoginException("Cannot get user/password");
        } 
        final String result[] = new String[]
        { 
            name.getName(),
            new String(password.getPassword())
        }; 

5
CodeRank
This code example shows how to use the following methods:clearPassword, getPassword
 
    @Override 
    public boolean login() throws LoginException { 
 
        NameCallback nameCallback = new NameCallback("Name : ");
        PasswordCallback passwordCallback = new PasswordCallback("Password : ", false);
        try { 
            callbackHandler.handle(new Callback[]{nameCallback, passwordCallback});
            String username = nameCallback.getName();
            String password = new String(passwordCallback.getPassword());
            nameCallback.setName("");
            passwordCallback.clearPassword();
            Customer customer = customerService.findCustomer(username, password);
 
            if (customer == null) {
                throw new LoginException("Authentication failed");
            } 
 
            return true; 
        } catch (Exception e) {
5
CodeRank
clearPassword Method Overview
Clear the retrieved password.
See Code Examples for other Java 8 PasswordCallback Methods: