Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problems with Validations and StringBuilder.

$
0
0
I'm working on this new project that involves 2 classes and a Demo to test them if a password is valid to terms. One class is testing a simple String for length of 6, uses atleast 1 Uppercase, uses atleast 1 lowercase, and atleast one digit. The second class is the same but involves StringBuilder to do the same. I'm lost this is my String class code so far. The loops and ifs are overwhelming my brain.

Specifically this code.
Am I supposed to use verifyLength, Up- upper, lo- lower, ... so on.

public class ValidS {

	public static boolean getLength(String pass) {
	
	if (pass.length() < 6){
	return false;
	}
	else{
	return true;}
	}
	
	public static boolean getUp(char pass){
	boolean gOb = false;
	
	if(Character.isUpperCase(pass)){
	gOb = true;
	}
	return gOb;
	}
	
	public static boolean getLow(char pass){
	boolean gOb = false;
	
	if(Character.isLowerCase(pass)){
	gOb = true;
	}
	return gOb;
	}
	
	public static boolean getNum(char pass){
	boolean gOb = false;
	
	if(Character.isDigit(pass)){
	gOb = true;
	}
	return gOb;
	}

	public static boolean getValid(String pass){
	
	boolean up = false;
	boolean lo = false;
	boolean di = false;
	boolean gOb = false;
	
	int index = 0;
	
	if (getLength(pass) == false){
	System.out.println("The password must be atleast 6 characters long");
	}
	
	while(up == false){
	for(index = 0; index < pass.length(); index++){
	up = getUp(password.chatAt(index));
	if(index == password.length() || up == true){
		}
	}
	
	index = 0;
	
	if(up == false) {
	System.out.println("Please use atleast one uppercase letter. ex.ABC ");
	}
	
	while(lo == false){
	for(index = 0; index < pass.length(); index++) {
	lo = getLo(password.charAt(index));
	if(index == password.length() || lo == true)
		}
	}
	
	index = 0;
	
	if (lo == false){
	System.out.println("Please use atleast one lowercase letter. ex.abc");
	}
	
	while(di == false){
	for(index = 0; index< pass.length(); index++){
	di = getNum(pass.charAt(index));
	if(index = password.length() || di == true)
		}
	}
	
	if(di == false)
	System.out.println("Please use atleast one number. ex.123");
	gOb = up && lo && di;
	return gOb;
		}
	}
}



Also could I do better with a If...Else If... to check those?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>