Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <unistd.h>
- //#include <fcntl.h>
- char username[30];
- char password[30];
- char password2[30];
- int n;
- void enterpw() {
- for (n = 0; n < 30; n++) {
- password[n] = '\0';
- password2[n] = '\0';
- }
- write(1, "\nPassword: ", 11);
- read(0, password, sizeof(password));
- write(1, "Confirm password: ", 18);
- read(0, password2, sizeof(password2));
- for (n = 0; n <= 30; n++) {
- if (password[n] != password2[n]) {
- write(1, "\nError: Passwords do not match. Try again.\n", 44);
- enterpw();
- }
- }
- }
- int main(void) {
- write(1, "\nPlease enter your username: ", 29);
- read(0, username, sizeof(username));
- enterpw();
- int fp = open("user.dat", O_WRONLY | O_CREAT, 0644);
- write(fp, username, sizeof(username));
- write(fp, password, sizeof(password));
- write(fp, password2, sizeof(password2));
- close(fp);
- write(1, "\nPasswords match. Data written to file.\n\n", 41);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement