Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import java.io.FileWriter;
  2. import java.util.Scanner;
  3. public class Validating {
  4.  
  5.  
  6. public static void main(String args[]){
  7. Scanner in = new Scanner (System.in);
  8. System.out.println("Enter your username");
  9. String user = in.nextLine();
  10. System.out.println("Enter your password");
  11. String pass = in.nextLine();
  12.  
  13. String symbols = "!@#$%^&*()_+{}:?><";
  14. boolean isUser = false, isPass = true;
  15. char [] symbolsArray = symbols.toCharArray();
  16.  
  17. if(user.length() < 9 || pass.length() < 9){
  18. System.out.println("Too many characters!");
  19. System.exit(0);
  20. }
  21.  
  22.  
  23. char userArray [] = user.toCharArray();
  24. char passArray [] = pass.toCharArray();
  25. // user validation
  26. for( int i = 0; i < userArray.length; i++) {
  27. for ( int j = 0; j < symbolsArray.length; j++){
  28. if ( userArray[i] == symbolsArray[j]) {
  29. System.out.println("Invalid user");
  30. break;
  31. }
  32. else{
  33. isUser = true;
  34. }
  35. }
  36. }
  37.  
  38. for( int i = 0; i < passArray.length; i++) {
  39. for ( int j = 0; j < symbolsArray.length; j++){
  40. if ( passArray[i] == symbolsArray[j]) {
  41. System.out.println("Invalid password");
  42. break;
  43. }
  44. else{
  45. System.out.println("Login success!");
  46. isPass = true;
  47. break;
  48. }
  49.  
  50. }}
  51.  
  52.  
  53.  
  54. if(isUser == true && isPass == true){
  55.  
  56. try{
  57. FileWriter fw=new FileWriter("C:\\records.txt");
  58. fw.write(user);
  59. fw.write(pass);
  60. fw.close();
  61. }catch(Exception e){System.out.println(e);}
  62. System.out.println("Success...");
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement