Can anyone help me with rewriting my pseudocode? Below is the pseudocode, and after that is the completed program.
Pseudocode:
DISPLAY Login information
PROMPT for username/password
output "Enter Username"
input userName
output "Enter password: "
input password
//If successful, display information pertaining to the specific user, as well as prompt for logout
IF User type 'quit'
Exit Program
VALIDATE User Credentials
IF NOT Validated
Check number of Invalid Attempts
IF user attempts equal three THEN
DISPLAY error message
output "You have reached the maximum number of login attempts, please contact your system administrator"
EXIT program
ELSE
DECREMENT Login attempts by one
//Inform User of remaining attempts
output "# attempts remaining"
LOOP to VALIDATE Credentials
ENDIF
ELSE
SET Username
MATCH Corresponding Role
DISPLAY Welcome message
ELSE
IF User type 'quit'
Exit Program
Completed Program:
public static void main(String[] args) throws Exception
{
//Scanner object that reads input
Scanner readInput=new Scanner(System.in);
//Keeps track of number of attempts
int attempts=0;
while(true)
{
//PROMPT for username/password
System.out.print("Enter username: ");
String uName=readInput.nextLine();
System.out.print("Enter password: ");
String original = readInput.nextLine();
//Convert the password with MD5hash
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(original.getBytes());
byte[] digest = md.digest();
StringBuffer sb = new StringBuffer();
for (byte b : digest)
{
sb.append(String.format("%02x", b & 0xff));
}
//Keep track whether login is successful or not
boolean authenticationSuccess=false;
Scanner readCred=new Scanner(new File("Credentials.txt"));
while(readCred.hasNextLine())
{
String record=readCred.nextLine();
String columns[]=record.split("\t");
//Check user name.
if(columns[0].trim().equals(uName))
{
if(columns[1].trim().equals(sb.toString()))
{
authenticationSuccess=true;
//Open the job file
Scanner readRole=new Scanner(new File(columns[3].trim()+".txt"));
//Display the information per job
while(readRole.hasNextLine())
{
System.out.println(readRole.nextLine());
}
break;
}
}
}
//Prompt user to logout
if(authenticationSuccess)
{
System.out.println("Logout? (y/n): ");
String choice=readInput.nextLine();
if(choice.toLowerCase().charAt(0)=='y')
{
System.out.println("You have logged out");
break;
}
else
{
authenticationSuccess=false;
}
}
else
{
attempts++;
//Maximum attempts, exit program
if(attempts==3)
{
System.out.println("You have reached the maximum number of login attempts, please contact your system administrator.");
break;
}
else
{
System.out.println("Try again!");
}
}
}
}
}
Here is the pseudocode I wrote:
In the main function
Initialize attempts to 0;
while true
print promt "Enter username"
Input username as uName
print promt "Enter password"
Input password as original
Create MessageDigest md
Update md to original
Create byte[] digest for md
Create a StringBuffer
for byte b : digest
Append String to sb
Initialize authenticationSuccess to false
Create scanner readCred for file Credentials.txt
while readCred.hasNextLine()
Let record read each line from file at a time
Let columns be an array which contains words in line
if columns[0] trimmed is equal to uName
if columns[1] trimmed is equal to sb
authenticationSuccess = true;
Open Job file with scanner readRole
Display information per job
if authenticationSuccess is true
print prompt "Logout? (y/n) : "
Read choice from user
convert choice to lowercase
if choice is equal to y
print prompt "You have logged out"
else
authenticationSuccess = false
else
Increment attempts by 1
if attempts == 3
print prompt "You have reached the maximum number of login attempts, please contact your system admin"
Break;
else
print prompt "Try again"
Can anyone help me with rewriting my pseudocode? Below is the pseudocode, and after that is...
Can someone fix the program below so it does what the picture
says it won't work for me.
import java.util.Scanner;
public class Userpass {
static String arr[];
static int i = 0;
public static void main(String[] args) {
String username, password;
int tries = 0, result;
do {
System.out.print("Enter the username: ");
username = readUserInput();
System.out.print("Enter the password: ");
password = readUserInput();
result = verifyCredentials(username, password);
tries++;
if (result == -1)
System.out.println("The username is incorrect!\n");
else if (result == -2)...
I need help ASAP on this, this is due at midnight PST. This is the current code I have. How can I allow the user to quit. My counting while loop works fine, but I would like it to not keep outputting username if a file was successfully opened. This is what is required. Prompt You have assumed the role of managing the technology infrastructure at a zoo. You will develop a working program (either an authentication system or a...
Hello Can you help to fix the program. When running, it still show Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: class Contact location: class ContactMap at ContactMap.main(ContactMap.java:40) C:\Users\user\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second) ************************ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class ContactMap { public static void main(String args[]) throws IOException { Scanner input=new Scanner(System.in); //Create a TreeMap ,...
I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...
Modify the below Java program to use exceptions if the password is wrong (WrongCredentials excpetion). import java.util.HashMap; import java.util.Map; import java.util.Scanner; class Role { String user, password, role; public Role(String user, String password, String role) { super(); this.user = user; this.password = password; this.role = role; } /** * @return the user */ public String getUser() { return user; } /** * @param user the user to set */ public void setUser(String user) { this.user = user; } /** *...
Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...
public static void main(String[] args) { int option=0; while(option<8){ Scanner input=new Scanner(System.in); System.out.println("Welcome! Please enter your name"); String name=input.next(); Person user= new Person(name); System.out.println("Your id: "+user.getID()); System.out.println("Login successful"); System.out.println("------------------------------"); while(option!=7){ System.out.println("1.Create and host a new meeting"); System.out.println("2.Cancel a meeting"); System.out.println("3.Attend an existing meeting"); System.out.println("4.Leave a meeting"); System.out.println("5.Display my meetings"); System.out.println("6.Display meetings organized by me"); System.out.println("7.Logout"); System.out.println("8.Exit the app"); option=input.nextInt(); switch(option){ case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break;...
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...
Hello, can get some help with simple pseudocode describing the steps for this program below? THUMBS UP always left for help! public class TimeDemo { private static Scanner keyboard; private static String enteredTime; private static Time now; public static void main (String [] args) { keyboard = new Scanner(System.in); char answer = 'Y'; enteredTime = null; String response; while (answer== 'Y') { System.out.print( "Enter a military time using the ##:##...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...