Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Instead of Scanner in 1.4

807603Oct 19 2007 — edited Oct 19 2007
Hi,
I doing password validation. Condition is character length should be 8 and it should have atleast 1 alphabet and 1 number. I have got code for doing this its working fine with 1.5 but not with 1.4.

Later i found that Scanner class is not present in 1.4. But i need to do the same functionality with 1.4. what can i do?

what can be used instead of Scanner ??

the value entered should be a string 'cos am getting the string from another file.

help needed..

Thanks in advance..
Here is my code..........

import java.util.Scanner;

/*
 * Created on Oct 19, 2007
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author jkumar
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Password {

	public static void main(String[] args) {
		System.out.println("Please enter a password");
		
		 
	      String password = "hereisth!@#password12";
	      		 
	       Scanner scan = new Scanner(password);	
	       String pass = scan.nextLine();
	       int length = pass.length();
	       int charCount = 0, intCount = 0;
	       byte b[] = pass.getBytes();
	       boolean errOccurred = false; 

	       errOccurred = length <7 && length > 19;

	       if (!errOccurred)
	       {
	           
	           for (int i = 0; i < b.length ; i++ )
	           {
	               charCount  = ((b[i] > 64 && b[i] < 91) 
	                            || (b[i] > 96 && b[i] < 123)) == true 
	                            ? ++charCount : charCount; 
	               intCount  = (b[i] > 47 && b[i] < 58) == true
	                            ? ++intCount : intCount; 
	           }
	       }

	       
	       errOccurred = errOccurred || charCount == 0 || intCount == 0; 
	       

	       if (errOccurred)
	       {
	           System.err.println("Passwords must contain a minimum of " +
	                               " 8 to 20 characters and must contain ateast" + 
	                               " one digit and character");
	       }
	       else
	           System.out.println("your password has been accepted");
		
	}
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 16 2007
Added on Oct 19 2007
27 comments
515 views