Advertisement
Guest User

Untitled

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