De La Salle University- Manila
Gokongwei College of Engineering
Lab Activity Number : 9 (Assignment)
Lab Activity Title : Strings
Date Performed : March 17, 2025
Date Submitted : March 17, 2025
Instructor : Marvil Graza
Name of Student : Sarah Gwyneth Zulueta
Student ID : 12300446
Subject / Section : LBYEC2A / EQ5
Remarks:
_______________________________________________________________
_______________________________________________________________
Student’s Signature : ________________
Machine Problem
Write a program for enhanced security and anti-fraud protection.
Use of string functions
System is encrypted with username and password
Password characters will change into asterisk per input
If the username and password are correct, display “VALID” otherwise “INVALID”
Example:
Username: animoLS
Password: ******
VALID!
Flowchart:
Codes:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define USERNAME "animoLS"
#define PASSWORD "secret"
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';
if (strcmp(inputUser, USERNAME) == 0 && strcmp(inputPass, PASSWORD) == 0) {
printf("\nVALID!\n");
} else {
printf("\nINVALID!\n");
}
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.