Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Radu Ciuca
- */
- public class PersonClass {
- //attributes which are required to specify person
- File loginFile = new File("login.txt");
- String username;
- String password;
- String usertype;
- String fullName;
- String gender;
- String phoneNo;
- String email;
- String DOB;
- public boolean LoggedIN = true;
- String setUtype;
- /*****************************************************************
- About: This functions which starts with set are for setting values for variables
- *****************************************************************/
- public void setPassword (String pword){
- password = pword;
- }
- public void setUsername (String uname){
- username = uname;
- }
- public void setUtype (String utype){
- usertype = utype;
- }
- /*****************************************************************
- About: This function is logging in user to a system and allocates
- relevant, in order to continue working.
- *****************************************************************/
- public boolean LogIn() throws FileNotFoundException, IOException
- {
- try {
- // TODO add your handling code here:
- Scanner sc = new Scanner(loginFile);
- String line = ""; //get data from line by line, then put it in variable line
- while(sc.hasNextLine())
- {
- line = sc.nextLine();
- String uname =line.substring(line.indexOf("username:")+ 10,
- line.indexOf(", password"));
- String pword =line.substring(line.indexOf("password:")+ 10,
- line.indexOf(", usertype:"));
- String utype = line.substring(line.indexOf("usertype: ")+ 10, line.indexOf(".;")).trim();
- //student, admin, tutor or parent?
- if(uname.equals(username) && pword.equals(password) && utype.equals(usertype))
- {
- //login
- if(utype.equals("admin"))
- {
- //jLabel3.setText("admin.");
- AdminStaff.mainForm.setVisible(true);
- }
- else if(utype.equals("parent"))
- {
- //jLabel3.setText("parent.");
- Parent.mainForm.setVisible(true);
- }
- else if (utype.equals("tutor"))
- {
- //jLabel3.setText("tutor.");
- Tutor.mainForm.setVisible(true);
- }
- else if(utype.equals("student"))
- {
- //jLabel3.setText("student.");
- Student.mainForm.setVisible(true);
- }
- //Person.mainForm.setVisible(true);
- break;
- }
- else
- {
- //don't login, show error
- }
- }
- //closing file
- sc.close();
- }
- catch (FileNotFoundException ex) {
- Logger.getLogger(PersonClass.class.getName()).log(Level.SEVERE, null, ex);
- }
- //returnign boolean value to get access in system
- return LoggedIN;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement