-->

(Major Project) Offline DataBase using Java


 A Offline DataBase - David Raj

• Install Program

This code is a part of a program that is used to install a software. It starts by creating a main folder for the software. Then it takes user input for the details required for the installation process. It takes the user's first name, last name, phone number, username and password. It then checks if the username and password entered by the user are the same. If they are the same, it adds the username and password to the ArrayList and saves the data in the main folder. It also adds the phone number to the ArrayList and generates a folder number for the user. Finally, it prints a message that the installation was successful and saves the folder number in the main folder.

• Method 1 : Password Case Sensitive

This code is a method used to check a password for certain criteria. The criteria that is being checked is if the password contains an uppercase letter, a lowercase letter, a numerical value, and a special character. The method uses a scanner to take input from the user, and then uses Pattern and Matcher objects to match the criteria. If the criteria is not met, the method prints out the criteria that the password should contain and asks the user to enter a new password. The method then calls itself with the new password, and the process is repeated until the criteria is met. Finally, the method returns the checked password.

• Method 2 : Username Generator

This code is generating a username from the given parameters. The fname parameter is a string that contains the user's first name. The lname parameter is a string that contains the user's last name. The phno parameter is a string that contains the user's phone number. The code creates a username by taking the first two characters of the last name, and then squaring the digits in the phone number and taking the first two of those. It then combines this with the first name to form the username. Finally, it prints out the suggested username.

• Method 3 : Folder no. Generator

This code is used to generate a folder number from a given phone number. The folder number is generated by taking the square of each alternate digit of the phone number and then taking the first 6 digits of the result. The code takes two parameters, an integer n and a string phno. The integer n is used to determine the output of the code. If n is 0, the code prints the folder number and returns it. If n is 1, the code returns the folder number without printing it. If n is any other value, the code returns an empty string. The code then calculates the folder number by looping through the phone number and taking the square of each alternate digit. The result is then stored in a string and the first 6 digits of the string are taken as the folder number. The folder number is then returned based on the value of n.

• Method 4 : Username Check (Existing)

This code is a method that checks if a username already exists in a database. It takes four parameters: username, fname, lname, and phno. It creates a Scanner object to read user input. It then checks if the username already exists in the database using the readdata() method. If the username already exists, it prints a message and calls the ungenerator() method. It then prompts the user to enter a new username and calls the uncheck() method again with the new username. If the username does not exist, it returns the username.

• Method 5 : Phone No. Check (Existing)

This code is a method that checks if a given phone number already exists in a database. It takes a String parameter called phno. It creates a Scanner object called sc and a String variable called phn. It then checks if the database contains the given phone number. If it does, it prints a message and prompts the user to enter a new phone number. It then calls the method again with the new phone number as a parameter. If the phone number does not exist in the database, it returns the phone number.

• Method 6 : Username Check (Sign In 1)

This code is a method that is used to check if a username exists. It takes in a String parameter called Username. It then creates a Scanner object to take in user input. It then prints out a message asking the user to check the username or re-enter the username. It then takes in an integer input from the user. If the user enters 0, it calls the forgot() method with two parameters. Finally, it prints out a message asking the user to re-enter the username and takes in the new username as a String. It then returns the new username.

• Method 7 : Password Check (Sign In 2)

This code is a part of a larger program that is used to sign in to an account. It is a method that is called when the user enters an incorrect password. It prompts the user to either check their password or change it. If the user chooses to change their password, it calls the changep() method and if they choose to check their password, it calls the forgot() method. It then prompts the user to enter a new password and returns the new password.

• Method 8 : Hide Password (Case Sensitive)

This code is used to hide the password when the user is signing in. The code takes an integer as an argument. If the integer is 0, it uses the System.console() method to read the password and store it in a char array. It then converts the char array to a String and returns it. If the integer is not 0, it uses the Scanner class to read the password and store it in a String. It then returns the String.

• Method 9 : Change Password

This code is used to change the password of a user. It takes the username as an argument and then asks the user to enter their phone number. It then reads the data from a file and checks if the username and phone number match. If they do, it asks the user to enter a new password and saves the data to the file. If the username and phone number do not match, it prints an error message and calls the same function again.

• Method 10 : Write

This code is used to write data to a file. It takes a file name as an argument and creates a file with that name in the "C:\DataBase\fnu" directory. It then prompts the user to enter the file name and stores it in the variable "filename". It then creates a DataInputStream object to read data from the System.in stream and a FileOutputStream object to write data to the file. It then reads data from the System.in stream and writes it to the file until the user enters the character '@'. Finally, it prints a message to the console indicating that the file has been saved.

• Method 11 : Open

This code is used to open a file from a given directory. The parameters passed to the method are an integer and a string. The integer is used to determine the directory from which the file is to be opened. If the integer is 0, the file is opened from the directory specified by the string parameter. If the integer is 1, the user is prompted to enter the file name and the file is opened from the directory specified by the string parameter. The file is then opened using a FileReader object and the contents of the file are printed out. Finally, the file is closed.

• Method 12 : Create File

This code creates a new file in the specified directory. It takes the file name as an input from the user and creates a file with that name in the directory "C:\\DataBase\\"+fnu+"\\". The absolute path of the file is then printed out.

• Method 13 : Create Folder

This code creates a folder in the specified directory. It takes a String parameter fnu and uses it to create a directory in the "C:\\DataBase\\" directory. It then prompts the user to enter the folder name and stores it in the variable filename. It then creates a File object with the filename and the fnu parameter and uses the mkdir() method to create the folder. Finally, it prints out the absolute path of the newly created folder.

• Method 14 : Selection

This code is a part of a program that allows a user to perform various file operations. It is a method named selection() which takes a String parameter fnu. It uses a Scanner object to take input from the user and stores it in an int variable named option. It then uses a switch statement to decide which operation to perform based on the value of option. The operations that can be performed are opening a file, writing to a file, creating a file, creating a folder, and listing files. If the user enters 6, the program prints a message and returns.

• Method 15 : Create Main Folder

This code creates a directory in the C:\DataBase folder. The parameter n is used to determine if the directory should be created in the DataBase folder or in a subfolder of the DataBase folder. If n is 0, the directory is created in the DataBase folder. If n is not 0, the folderno() method is called to generate a name for the subfolder and the directory is created in the subfolder. The parameter phno is used to generate the name of the subfolder. The Scanner object is used to read user input. The File object is used to create the directory.

• Method 16 : List Files

This code is used to list all the files in a directory. It takes the directory path as an argument and prints out the list of files in the directory. First, a Scanner object is created to read user input. Then, a File object is created with the given directory path. The list() method of the File object is used to get an array of all the files in the directory. Finally, a for loop is used to iterate through the array and print out the list of files.

• Method 17 : List Folders

This code is used to list all the files and folders in a directory. It takes the directory path as an input and prints the name of all the files and folders present in the directory. It first creates a Scanner object to take the directory path as an input. Then it creates a File object with the given directory path. It then creates an array of File objects with the list of files and folders present in the directory. It then iterates through the array and checks if the object is a file or a folder. If it is a file, it prints the file name. If it is a folder, it prints the folder name.

• Method 18 : Save Data

This code is used to save data in a file. The method takes two parameters, an integer 'i' and an ArrayList of Strings 'data'. Depending on the value of 'i', the name of the file is set to either 'usernames', 'passwords', 'phnos' or 'fno'. A FileOutputStream is created with the file path and name. An ObjectOutputStream is created with the FileOutputStream as a parameter. The ArrayList 'data' is written to the file using the writeObject() method of the ObjectOutputStream. Finally, the flush() and close() methods are called to flush the data to the file and close the stream.

• Method 19 : Read Data

This code reads data from a file and stores it in an ArrayList. The file is located at "C:\\DataBase\\" and the name of the file is determined by the parameter i. If i is 0, the file is "usernames.ser", if i is 1, the file is "passwords.ser", if i is 2, the file is "phnos.ser" and if i is 3, the file is "fno.ser". The data is read using a FileInputStream and an ObjectInputStream and is stored in an ArrayList. The ArrayList is then returned.

• Method 20 : Forgot

This code is a method that is used to retrieve a forgotten username or password. It takes two parameters, a username and an integer. The integer is used to determine whether the user is trying to retrieve their username or password. The code begins by creating a Scanner object to read user input. It then prompts the user to enter their phone number. If the integer parameter is 0, the code checks if the phone number exists in the data. If it does, it prints out the username associated with the phone number. If the phone number does not exist, it prints out an error message. If the integer parameter is 1, the code checks if the username and phone number match. If they do, it prints out the password associated with the phone number. If they do not match, it prints out an error message and calls the method again with the same parameters.

• Method 21 : Print Details of the staff

This code is used to print out the details of staff members. The method staff() throws an IOException which means that it can throw an exception if an input or output operation fails. The method reads data from four different files and stores them in four different ArrayLists. The for loop is used to iterate through the ArrayLists and print out the details of the staff members. The details printed out are the serial number, username, password, phone number, and folder number.

• Method 22 : Administrator Options

This code is a method named adoptions() which throws an IOException. It contains a while loop which prints out three options for the user to choose from. Depending on the user's choice, the code will either list the folders, get the details of the staff, or sign out. If the user chooses to open a folder, the code will check if the folder exists and if it does, it will list the folder and open it. If the folder does not exist, the user will be asked to re-enter the folder number.

 Method 23 : Otp Check

This code is responsible for generating an One Time Password (OTP) and verifying it against a user provided value. It starts by creating a Scanner object to read user input and a LocalTime object to get the time. It then extracts the time as a string and creates a new string, phn, that takes the square of each digit from the time string. The next step is to take the last 4 digits of phn and assign it to tm. The code then prints the OTP, prompts the user for input and verifies the OTP against the user provided value. If the OTP matches, the code returns the phone number, otherwise it will print an error message and recall the otp method.

• Main Method (DataBase):

This code is the main method of a program which is used to sign up, sign in and log in as an administrator. The main method starts by creating four ArrayLists to store usernames, passwords, phone numbers and folder numbers. It then creates a Scanner object to take user input. The program then enters a while loop which will run until the user exits the program. It prints out a list of options for the user to choose from and takes their input. The program then enters a switch statement which will execute different code depending on the user's input. If the user chooses option 1, the program will prompt the user to enter their first and last name, phone number, username and password. It will then check if the username and password are valid and if they are, it will save the user's information to the ArrayLists and create a folder for the user. If the user chooses option 2, the program will prompt the user to enter their username and password. It will then check if the username and password are valid and if they are, it will allow the user to access their folder. If the user chooses option 3, the program will prompt the user to enter their username and password. It will then check if the username and password are valid and if they are, it will allow the user to access the administrator options. If the user chooses any other option, the program will exit.


To know the program code and outputs : Contact me