KeeganT

Ch6Test Modified

Apr 9th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package ch6test;
  2. import java.util.Scanner;
  3.  
  4. public class Ch6Test
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner sc=new Scanner(System.in);
  9.         System.out.println("Enter email: ");
  10.         String email=sc.nextLine();
  11.         System.out.println("Enter password: ");
  12.         String password=sc.nextLine();
  13.         char[] passArray=password.toCharArray();
  14.         String symbols="*@>$";
  15.         char[] symbolArray=symbols.toCharArray();
  16.        
  17.         //EMAIL VERIFICATION
  18.         boolean emailValid=true;
  19.         String reverse="";
  20.         if(email.indexOf("hwdsb.on.ca")==-1)emailValid=false;
  21.         int atSymbol=email.indexOf('@');
  22.         substring1=email.substr(0,atSymbol);
  23.         if(beforeAtSymbol.length()<3)emailValid=false;
  24.         char[] b4At=substring1.toCharArray();
  25.         for(int c=beforeAtSymbol.length()-1;c>-1;c--)reverse+=b4At[c];
  26.        
  27.         //PASSWORD VERIFICATION
  28.         boolean passwordValid=false;
  29.         if(!password.length()>=6)passwordValid=false;
  30.         if(!(passArray[0]>=97&&passArray[0]<=122))passwordValid=false;
  31.         if(!(passArray[0]>=65&&passArray[0]<=90))passwordValid=false;
  32.         for(int c=0;c<password.length();c++)if(passArray[c]!=' ')
  33.         {
  34.             passwordValid=false;
  35.             break;
  36.         }
  37.         for(int c=0;c<password.length();c++)if(!(passArray[c]>=48&&passArray[c]<=57))passwordValid=false;
  38.         for(int c=0;c<password.length();c++)for(int x=0;x<4;x++)if(passArray[c]==symbolArray[x])oneSymbol=true;
  39.         if(!(password.contains(beforeAtSymbol)==true)||!(password.contains(reverse)==true))passwordValid=false;
  40.        
  41.         if(emailValid==true&&passwordValid==true)System.out.println("Email and password accepted.");
  42.         else System.out.println("Email or Password not accepted!");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment