Java Program I have most of the code done but I am having tr

Java Program

I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements to complete the program will be appreciated.

Companies with lots of employees need to manage user information and passwords. It would be helpful to have the facility to generate a userid and password when a new employee is entered.

Create a class, User, that manages user info.

The class must store first name, last name, phone number, userid, and password.

The class must generate the id based on first initial, lastname.

The class must generate a random based 6 position password.

The private information should all be strings.

The class must allow for changes to these fields.

The class must allow for display of all the fields but password

The class must allow for display of the fields including password

The class must allow for the comparison of userid and password, returning true or false.

Write a driver that instantiates several instances of the class User, modifies several field, displays the contents, performs a comparison of userid and password against keyboard input. The purpose of the driver is to demonstrate that the class features are working.

You’ll need to write a constructor that creates the object with information passed to it. The constructor will have to generate the userid and generate a random password.   You should use private methods for generating the userid and password that the constructor calls.

Constructor methods must include:

            Default constructor

Requires no parameters

                        Sets variables to default values – empty strings

            Overloaded constructor

                        Passed strings for first name, last name, and phone

                        Invokes private methods to create userid and password

Mutator methods must include:

updateName

Allow updating of first & last names. Accepts 2 strings as input

Returns void

updatePhone

Allow updating of phone number. Accepts 1 string as input

Returns void

updatePassword,

Allow updating of password.   Will allow setting to a specific password

Accepts 1 string as input

Returns void

updateUserID.

Allow updating of Userid

                        Will call private function to generate

Returns void

Accessor methods must include:

displayInfo

Doesn’t display the password and displays a formatted line using System.out.print

Returns void

            displayInfoAll

Displays all info including the password on a formatted line using System.out.print

Returns void

            isPasswordEqual

                        Compares a password passed to the method with the one stored.

Returns true or false

            isUseridEqual

                        Compares a userid passed to the method with the one stored.

Returns true or false

Private methods must include:

createUserid

Generates id based on first initial, last name

Returns void

            createPassword

Generates random password

Returns void

Complete all the requirements above. Generate a 6 position mixed upper/lower case alpha password with alternating consonants & vowels

Documentation is required

Class:User.

import java.util.Random;

public class User {

   private String first_name;
   private String last_name;
   private String phone_number;
   private static String user_name;
   private static String password;
  
   public User(){
       first_name=\"\";
       last_name=\"\";
       phone_number=\"\";
       user_name=\"\";
       password=\"\";
   }
   public User(String firstname,String lastname,String phonenumber){
       first_name=firstname;
       last_name=lastname;
       phone_number=phonenumber;
       User user=new User();
       user.createUserid(firstname, lastname);
       user.createPassword();
      
   }
  
  
  
   public void updateName(String first_name, String last_name) {
       this.first_name = first_name;
       this.last_name = last_name;
       System.out.println(\"Updated firstname is \"+first_name+\" and lastname is \"+last_name);
   }
  
   public void updatePhone(String phone_number) {
       this.phone_number = phone_number;
       System.out.println(\"Updated phone number is \"+phone_number);
   }
  
   public void updatePassword(String password) {
       this.password = password;
   }
  
   public void updateUserID(String user_name) {
       this.user_name = user_name;
   }
  
  
   public void displayInfo() {
       System.out.println(first_name+\",\"+last_name+\",\"+phone_number+\",\"+user_name);
   }
  
   public void displayInfoAll() {
       System.out.println(first_name+\",\"+last_name+\",\"+phone_number+\",\"+user_name+\",\"+password);
   }
  
  
   public boolean isPasswordEqual(String user_input){
       boolean flag=true;
       if(password.equals(password)){
           flag=true;
           return flag;
       }
       else flag=false;
      
       return flag;
   }
  
  
   public boolean isUseridEqual(String user_input){
       boolean flag=true;
       if(user_input.equals(user_name)){
           flag=true;
           return flag;
       }
       else flag=false;
      
       return flag;
   }
  
  
  
  
   private void createUserid(String firstname,String lastname){
      
       StringBuilder user_id=new StringBuilder();
       user_id.append(firstname.charAt(0));
       for(int i=0;i            user_id.append(lastname.charAt(i));
       }
      
       /*=============Adding 3character sequence to remove duplication=====================*/
       String str=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";
       Random random=new Random();
       for(int i=1;i<=3;i++){
           user_id.append(str.charAt(random.nextInt(26)));
       }
       /*==================================================================================*/
       System.out.println(\"The generated userId is \"+user_id);  
       user_name=user_id.toString();
      
      
   }
   private void createPassword(){
       String str=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";
       Random random=new Random();
       StringBuilder pswrd=new StringBuilder();
       for(int i=1;i<=6;i++){
           pswrd.append(str.charAt(random.nextInt(26)));
       }
       password=pswrd.toString();
       System.out.println(\"The generated password is \"+pswrd);
   }
  
  
  
}

ClientClass:DriverClass.java

public class DriverClass {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       User user=new User(\"abc123\",\"xyz123\",\"0987654321\");
       user.displayInfo();
       user.displayInfoAll();
       user.updateName(\"abc\", \"xyz\");
       user.updatePassword(\"abcdef\");
       user.updatePhone(\"1234567890\");
       user.updateUserID(\"abcxyz\");

   }

}

Solution

Please import the SecureRandom class and try this string method.I tried it :

static final String PassLen = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";

static SecureRandom rnd = new SecureRandom();

protected String passWord( int len ){

   StringBuilder sbuilder = new StringBuilder( len );

   len=6;

   for( int i = 0; i < 6; i++ )

      sbuilder.append(PassLen.charAt( rnd.nextInt(PassLen.length()) ) );

   return sbuilder.toString();

}

Java Program I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements t
Java Program I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements t
Java Program I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements t
Java Program I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements t
Java Program I have most of the code done but I am having trouble with generating the password. Any help to correct/improve the code and meet the requirements t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site