Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Check {
- public static boolean checkUsername(String user){
- return checkLetterUser(user) && checkLengthUser(user) && checkDot(user);
- }
- public static boolean checkPassword(String pwd, String user){
- return checkLengthPwd(pwd) && checkSamePwd(pwd,user);
- }
- public static boolean checkLengthUser(String user) {
- int lenu = user.length();
- return (lenu > 4 && lenu < 225);
- }
- public static boolean checkLetterUser(String user) { //BUG : capital letter runs false
- String letter = "abcdefghijklmnopqrstuvwxyz";
- String space = " \\";
- String first = user.toLowerCase().substring(0,1);
- return (letter.indexOf(first) != -1) && (user.indexOf(space) == -1);
- }
- public static boolean checkDot(String user) {
- return user.indexOf("..") == -1;
- }
- public static boolean checkLengthPwd(String pwd) {
- int lenp = pwd.length();
- return (lenp > 4 && lenp < 225);
- }
- public static boolean checkSamePwd(String pwd, String user) {
- String small = user.toLowerCase();
- return (pwd.equals(small));
- }
- public static void main (String [] args) {
- Scanner sc = new Scanner (System.in);
- System.out.print("Username : ");
- String user = sc.nextLine();
- //String first = user.toLowerCase().substring(0,1);
- //System.out.println(first);
- String s1 = (checkUsername(user)) ? "Y" : "N";
- System.out.println(s1);
- System.out.print("Password : ");
- String pwd = sc.nextLine();
- String s2 = (checkPassword(pwd,user)) ? "Y" : "N";
- System.out.println(s2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement