Suppose You are an application developer for your company. You are conducting a code review of a
Windows Forms application that was developed by another developer. The application
includes a function named Logon(), which validates a users logon credentials. The function
displays a dialog box for the user to enter the users credentials, and the function validates those
credentials by using a database.
The function returns a value of 0 if the users password is incorrect, a value of 1 if the users user
ID is incorrect, and a value of 2 if both are correct. Users should receive access to the application
only if the function returns a value of 2. A function named EndApp() is used to exit the application.
The application must display a message to the user, depending on the result of the Logon()
function.
The application contains the following code segment.
int logonresult = Logon();
switch(logonresult) {
case 0:
MessageBox.Show("User name is OK, password incorrect.");
break;
case 1:
MessageBox.Show("User name is incorrect.");
break;
default:
MessageBox.Show("Welcome!");
break;
}
if(logonresult != 2) {
EndApp();
}
You need to improve the security of this code segment while maintaining its funtionality. You
decide to replace the existing code segment.
Which code segment should you use?
A. if(Logon() != 2) {
Console.WriteLine("Logon error.");
EndApp();
}
B. if(Logon() != 2) {
Console.WriteLine("Logon error.");
EndApp();
}
else {
MessageBox.Show("Welcome!");
}
C. int logonresult = Logon();
switch(logonresult) {
case 0:
MessageBox.Show("User name is OK, password incorrect.");
EndApp();
break;
case 1:
MessageBox.Show("User name is incorrect.");
EndApp();
break;
default:
MessageBox.Show("Welcome!");
break;
}
D. int logonresult = Logon();
if(logonresult == 2) {
MessageBox.Show("Welcome!");
}
else {
MessageBox.Show("User name or password was incorrect.");
EndApp();
}

Submitted by: Administrator
D. int logonresult = Logon();
if(logonresult == 2) {
MessageBox.Show("Welcome!");
}
else {
MessageBox.Show("User name or password was incorrect.");
EndApp();
}
Submitted by: Administrator

Read Online MCSD.NET - 70-340 Exam Job Interview Questions And Answers