Class PasswordService

java.lang.Object
com.articulate.sigma.PasswordService
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener

@WebListener public final class PasswordService extends Object implements javax.servlet.ServletContextListener
A class that encrypts a string and checks it against another stored encrypted string, in order to validate a user login.
  • Field Details

    • JDBC_CREATE_DB

      public static final String JDBC_CREATE_DB
    • JDBC_ACCESS_DB

      public static final String JDBC_ACCESS_DB
    • INITIAL_ADMIN_USER

      public static final String INITIAL_ADMIN_USER
      See Also:
    • conn

      public Connection conn
  • Constructor Details

    • PasswordService

      public PasswordService()
      Create an instance of PasswordService
  • Method Details

    • contextInitialized

      public void contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)
      Specified by:
      contextInitialized in interface javax.servlet.ServletContextListener
    • contextDestroyed

      public void contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)
      Specified by:
      contextDestroyed in interface javax.servlet.ServletContextListener
    • encrypt

      public String encrypt(String plaintext)
      Encrypts a string with a deterministic algorithm. Thanks to https://howtodoinjava.com/security/how-to-generate-secure-password-hash-md5-sha-pbkdf2-bcrypt-examples/
    • getInstance

      public static PasswordService getInstance()
    • authenticate

      public boolean authenticate(String username, String pass)
      Take a user name and an encrypted password and compare it to an existing collection of users with encrypted passwords.
    • userExists

      public boolean userExists(String username)
    • userIDs

      public Set<String> userIDs()
    • deleteUser

      public void deleteUser(String uname)
    • login

      public void login()
    • mailModerator

      public void mailModerator(User user)
      Sends the moderator an email requesting a user to be registered a Sigma account
      Parameters:
      user - the user information to register an account for
    • register

      public void register()
      Command line initiated method for registering a Sigma user with role guest.
    • onlineRegister

      public void onlineRegister(User u)
    • addUser

      public User addUser(String login, String p, String e, String role)
      The working utility to add a user to the DB
      Parameters:
      login - the user name
      p - user password (will be encrypted)
      e - user email
      role - user role
      Returns:
      an instance of the user to add to the DB
    • getAdminEmails

      public List<String> getAdminEmails()
      Return a list of all admin users' email addresses.
    • createAdmin

      public void createAdmin()
      Creates an admin user using the console for user input
    • createUser

      public void createUser(String user)
      Creates a new user with role user
      Parameters:
      user - the user name
    • changeUserRole

      public void changeUserRole(String id)
    • changeUserPassword

      public void changeUserPassword(String username, String newPassword)
    • showHelp

      public static void showHelp()
    • main

      public static void main(String[] args)
      Command line entry point
      Parameters:
      args - given command line arguments