Find all passwords

Report a typo

Write a program searching for passwords in a given text. It is known that:

  • a password consists of digits and/or Latin upper- and lowercase letters in any combination;
  • a password always follows the word "password" (it can be written in upper- and/or lowercase letters) but can be separated from it by any number of whitespaces and colon : characters.

Output all passwords found in the text, each password starting with a new line. If the text does not contain any passwords, output "No passwords found." without quotes.

Try to use Matcher and Pattern to solve it. All the needed modules are already imported.

Sample Input 1:

My email [email protected] with password    SECRET115. Here is my old PASSWORD: PASS.

Sample Output 1:

SECRET115
PASS

Sample Input 2:

My email is [email protected].

Sample Output 2:

No passwords found.
Write a program in Java 17
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String text = scanner.nextLine();

// write your code here
}
}
___

Create a free account to access the full topic