Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. package PIO;
  2.  
  3. import java.awt.geom.FlatteningPathIterator;
  4. import java.util.ArrayList;
  5.  
  6. public class Password {
  7.  
  8. public User user;
  9. public String name;
  10. public static String password;
  11. public static ArrayList<User> users = new ArrayList<User>();
  12. public static boolean isCorrectPassword(User user){
  13. password = user.password;
  14. boolean posible = true;
  15. if(!notSamePass(user)){posible = false; System.out.println("hasło zostało użyte przez użytkownika");} else {
  16. if(!UserExist(user.name)) {posible = false; System.out.println("nie ma takiego użytkownika");} else{
  17. if(!minLenght(password)) {posible = false;System.out.println("Hasło za krótkie");} else {
  18. if(!polskieZnaki(password)) {posible = false;System.out.println("Hasło zawiera polskie znaki");} else {
  19. if(!polskieZnaki(password)) {posible = false;System.out.println("Hasło zawiera polskie znaki");} else {
  20. if(!duzaLitera(password)) {posible = false;System.out.println("Hasło nie zawiera DUŻEJ litery");} else {
  21. if(!cyfra(password)) {posible = false;System.out.println("Hasło nie zawiera Cyfry");} else {
  22. if(!znakiSpecjalne(password)) {posible = false;System.out.println("Hasło zawiera niedozwolone znaki specjalne");} else {
  23. if(!znakiSpecjalne2(password)) {posible = false;System.out.println("Hasło nie zawiera znaków specjalnych");} else
  24. {
  25. System.out.println("Hasło zostało zmienione ;) ");
  26. int znal = 0;
  27. for(int i = 0;i<user.old_pass.length&& znal==0;i++){
  28. if(user.old_pass[i].equals("")){
  29. znal = 1 ;
  30. user.old_pass[i]=password;
  31. }
  32.  
  33. }
  34. if(znal == 0 ) {
  35. user.old_pass[1]=user.old_pass[0];
  36. user.old_pass[2]=user.old_pass[1];
  37. user.old_pass[0] = password;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }
  48. }
  49. }}
  50. return posible;
  51. }
  52.  
  53.  
  54. private static boolean notSamePass(User user2) {
  55. String name = user2.name;
  56. String password = user2.password;
  57. for(int i=0;i<user2.old_pass.length;i++){
  58. if(password.equals(user2.old_pass[i])) return false;
  59. }
  60. return true;
  61. }
  62.  
  63.  
  64. private static boolean znakiSpecjalne2(String password2) {
  65. for(int i=0;i<password2.length();i++){
  66. char c = password2.charAt(i);
  67. int x = (int) c;
  68. if((x>=33&&x<=46) || (x>=59&&x<=64) || (x>=91&&x<=96) || (x>=123&&x<=126)) return true;
  69.  
  70. }
  71. return false;
  72. }
  73.  
  74.  
  75. private static boolean znakiSpecjalne(String password2) {
  76. for(int i=0;i<password2.length();i++){
  77. char c = password2.charAt(i);
  78. int x = (int) c;
  79. if((x==32||x==47||x==58)) return false;
  80.  
  81. }
  82. return true;
  83. }
  84.  
  85.  
  86. private static boolean cyfra(String password2) {
  87. for(int i=0;i<password2.length();i++){
  88. char c = password2.charAt(i);
  89. int x = (int) c;
  90. if((x>=48&&x<=57)) return true;
  91.  
  92. }
  93. return false;
  94. }
  95.  
  96.  
  97. private static boolean duzaLitera(String password2) {
  98. for(int i=0;i<password2.length();i++){
  99. char c = password2.charAt(i);
  100. int x = (int) c;
  101. if((x>=65&&x<=90)) return true;
  102.  
  103. }
  104. return false;
  105. }
  106.  
  107.  
  108. private static boolean polskieZnaki(String password2) {
  109. for(int i=0;i<password2.length();i++){
  110. char c = password2.charAt(i);
  111. int x = (int) c;
  112. if((x>=0&&x<=127)) {} else {
  113. return false;
  114. }
  115. }
  116. return true;
  117. }
  118.  
  119.  
  120. private static boolean minLenght(String password2) {
  121. if(password2.length()<8) return false; else return true;
  122.  
  123. }
  124.  
  125.  
  126. private static boolean UserExist(String user) {
  127. for(int i=0;i<users.size();i++){
  128. if(users.get(i).name.equals(user)) return true;
  129. }
  130. return false;
  131. }
  132.  
  133.  
  134.  
  135. public static void main(String[] args) {
  136.  
  137. User user = new User("Alex", "Roma");
  138. users.add(user);
  139. user = new User("Alex", "hkjhgLj@g4jghj");
  140. System.out.println(isCorrectPassword(user));
  141. System.out.println(isCorrectPassword(user));
  142. user.password="sdaF1!dasfafafa";
  143. System.out.println(isCorrectPassword(user));
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement