Advertisement
Guest User

Untitled

a guest
Aug 8th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. char username[30];
  2. char password[30];
  3. char password2[30];
  4. int n;
  5.  
  6. void enterpw() {
  7.        
  8.         for (n = 0; n <= 30; n++) {
  9.                 password[n] = '\0';
  10.                 password2[n] = '\0';
  11.         }
  12.  
  13.         write(1, "\nPassword: ", 11);
  14.         read(0, password, sizeof(password));
  15.  
  16.         write(1, "Confirm password: ", 18);
  17.         read(0, password2, sizeof(password2));
  18.  
  19.         for (n = 0; n <= 30; n++) {
  20.                
  21.                 if (password[n] != password2[n]) {
  22.                         write(1, "\nError: Passwords do not match. Try again.\n", 44);
  23.                         enterpw();
  24.                 }
  25.         }
  26. }
  27.  
  28. int main(void) {
  29.  
  30.         write(1, "\nPlease enter your username: ", 29);
  31.         read(0, username, sizeof(username));
  32.  
  33.         enterpw();
  34.  
  35.         int fp = open("user.dat", O_WRONLY | O_CREAT, 0644);
  36.         write(fp, username, sizeof(username));
  37.         write(fp, password, sizeof(password));
  38.         write(fp, password2, sizeof(password2));
  39.         close(fp);
  40.  
  41.         write(1, "\nPasswords match. Data written to file.\n\n", 41);
  42.         return(0);
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement