Java Scanner Read readPassword(String format, Object... args)

Here you can find the source of readPassword(String format, Object... args)

Description

read Password

License

Open Source License

Declaration

private static char[] readPassword(String format, Object... args) 

Method Source Code

//package com.java2s;
/*//from w w  w  . j a  v  a2s  .c o  m
Copyright 2016 Seth Traverse
    
This file is part of SecureFiles.
    
SecureFiles is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
SecureFiles is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with SecureFiles.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Scanner;

public class Main {
    private static char[] readPassword(String format, Object... args) {
        if (System.console() != null)
            return System.console().readPassword(format, args);
        System.out.println("WARNING -> Console password input unsupported, password entry in insecure mode!");
        return readLine(format, args).toCharArray();
    }

    private static String readLine(String format, Object... args) {
        System.out.print(String.format(format, args));
        return new Scanner(System.in).nextLine();
    }
}

Related

  1. readFromReader(Scanner scanner)
  2. readFromScanner(Scanner scanner)
  3. readInt(String prompt)
  4. readLine(String format, Object... args)
  5. readMatrix(Scanner in, int n)
  6. readPositiveInt(String message, Scanner input)
  7. readSystemInToIntArrayList()
  8. readWholeString(Scanner s)