Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileWriter;
- import java.util.Scanner;
- public class Validating {
- public static void main(String args[]){
- Scanner in = new Scanner (System.in);
- System.out.println("Enter your username");
- String user = in.nextLine();
- System.out.println("Enter your password");
- String pass = in.nextLine();
- String symbols = "!@#$%^&*()_+{}:?><";
- boolean isUser = false, isPass = true;
- char [] symbolsArray = symbols.toCharArray();
- if(user.length() < 9 || pass.length() < 9){
- System.out.println("Too many characters!");
- System.exit(0);
- }
- char userArray [] = user.toCharArray();
- char passArray [] = pass.toCharArray();
- // user validation
- for( int i = 0; i < userArray.length; i++) {
- for ( int j = 0; j < symbolsArray.length; j++){
- if ( userArray[i] == symbolsArray[j]) {
- System.out.println("Invalid user");
- break;
- }
- else{
- isUser = true;
- }
- }
- }
- for( int i = 0; i < passArray.length; i++) {
- for ( int j = 0; j < symbolsArray.length; j++){
- if ( passArray[i] == symbolsArray[j]) {
- System.out.println("Invalid password");
- break;
- }
- else{
- System.out.println("Login success!");
- isPass = true;
- break;
- }
- }}
- if(isUser == true && isPass == true){
- try{
- FileWriter fw=new FileWriter("C:\\records.txt");
- fw.write(user);
- fw.write(pass);
- fw.close();
- }catch(Exception e){System.out.println(e);}
- System.out.println("Success...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement