Zulueta - Lab Activity 9
Zulueta - Lab Activity 9
Remarks:
_______________________________________________________________
_______________________________________________________________
Example:
Username: animoLS
Password: ******
VALID!
Flowchart:
Codes:
#include <stdio.h>
#include <string.h>
#include <conio.h>
int main() {
char inputUser[20], inputPass[20];
char ch;
int i = 0;
printf("Username: ");
scanf("%s", inputUser);
printf("Password: ");
while (1) {
ch = getch();
if (ch == 13)
break;
else if (ch == 8 && i > 0) {
printf("\b \b");
i--;
} else if (ch != 8) {
inputPass[i++] = ch;
printf("*");
}
}
inputPass[i] = '\0';
return 0;
}
Output Screenshots:
Conclusion:
In this exercise, I learned how to write simple authentication system using string
function and password masking in C. For security reasons, the password was hidden
using asterisks when the user entered in the password during the program. This
exercise taught me the internals of such systems, which further reinforced how
important data protection is.
With `strcmp()`, I could compare what was provided to the system by the user against
predefined credentials such that only valid users could obtain access. Hence, I also
used `getch()` to secure the input of passwords, because unlike in a Display Mode,
characters are not displayed on the screen, which reduces the chance of password theft
through shoulder surfing. Moreover, I started to learn how to deal with special keys,
such as the Enter key (`\r`) when submitting input fields and the Backspace key (`\b`) for
allowing the user to correct mistakes.
Finally, this exercise has shown that input validation is an essential thing to prevent
unauthorized access. The system responded with message “INVALID” if the entered
credential was incorrect instead of granting access. This helped reenforce the secure
coding practices and how they prevent fraud.
I found this hands-on activity introduced a solid base on basic security methodology in
the C programming language. It helped me to become more acquainted with the use of
strings, handling of the input and authentication — all of which are critical skills to
possess in creating secure software applications.