Guest User

Untitled

a guest
Feb 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. Problem :
  2. Some computer programs try to prevent easily guessable passwords being used, by rejecting those that do not meet some simple rules. One simple rule is to reject passwords which contain any sequence of letters immediately followed by the same sequence.
  3.  
  4. For example:
  5.  
  6. APPLE Rejected (P is repeated)
  7. CUCUMBER Rejected (CU is repeated)
  8. ONION Accepted (ON is not immediately repeated)
  9. APRICOT Accepted
  10.  
  11. Write a program which takes a password string as input (between 1 and 10 upper case letters) and then prints 'Rejected' if the password is rejected, or 'Accepted' otherwise. Your program should then terminate.
  12.  
  13. Answer:
  14.  
  15. #include<stdio.h>
  16. #include<conio.h>
  17. #include<string.h>
  18. #include<ctype.h>
  19. void verifyPassword(char *s);
  20. int static error=0;
  21. void main()
  22. {
  23. char pwd[10];
  24. clrscr();
  25. do
  26. {
  27. error=0;
  28. printf("\nEnter Password:");
  29. scanf("%s",pwd);
  30. //Verifying length of password (1-10)
  31. if(strlen(pwd)>10)
  32. {
  33. printf("\nPassword Rejected:Length more than 10 characters");
  34. error=1;
  35. }
  36. for(int k=0;k<strlen(pwd);k++)
  37. {
  38.  
  39. //Verifying password is in uppercase
  40. if(isupper(pwd[k])==0)
  41. {
  42. printf("\nPassword Rejected:Enter password in uppercase letters\n");
  43. error=1;break;
  44. }
  45. }
  46. verifyPassword(pwd);
  47. }while(error==1);
  48. printf("\nPassword Accepted");
  49. getch();
  50. }
  51. void verifyPassword(char *s)
  52. {
  53. char a[1],b[1];
  54.  
  55. //Verifying password has repeated characters
  56. for (int i=0;i<strlen(s);i++)
  57. {
  58. if(s[i]==s[i+1])
  59. {
  60. printf("\nPassword Rejected :%c repeated in password",s[i]);
  61. error=1;
  62. }
  63. }
  64. //Verifying password has string of size 2 repeated consecutively
  65. for(int j=0;j<strlen(s);j++)
  66. {
  67. a[0]=s[j];
  68. a[1]=s[j+1];
  69. b[0]=s[j+2];
  70. b[1]=s[j+3];
  71.  
  72. if((a[0]==b[0]) && (a[1]==b[1]))
  73. {
  74. printf("\n Password Rejected: %c%c string repeated consecutively",a[0],a[1]);
  75. error=1;
  76. }
  77.  
  78. }
  79.  
  80. }
Add Comment
Please, Sign In to add comment