Package com.cloud.serverpak.services
Class AuthServiceBD
java.lang.Object
com.cloud.serverpak.services.AuthServiceBD
- All Implemented Interfaces:
AuthService
A class that works with a user Database. Designed to
perform CRUD operations on user records.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ConnectionConnection to the database.private final Base64.EncoderData encryption algorithm.private final List<AuthServiceBD.User>A list that stores a list of all users from the database.private static final org.apache.logging.log4j.LoggerThe logger variable.private static List<MainHandler>private static StatementA variable for working with the database. -
Constructor Summary
ConstructorsConstructorDescriptionThe constructor starts a connection to the Database and loads the list of users. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<MainHandler>getNickByLoginPass(String login, String pass) Returns the user's Name by his Username and Password.voidLoads all users from the Database to the list of users on the server.booleanregisterNewUser(String nickName, String login, String pass) Registers a new user, and throws an exception if it is impossible.voidstart()Connects the connection to the Database, and creates a statement object.voidstop()Closes the Database connection.
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGERThe logger variable. -
listUser
A list that stores a list of all users from the database. -
mainHandlerList
-
connection
Connection to the database. -
stmt
A variable for working with the database. -
encoder
Data encryption algorithm.
-
-
Constructor Details
-
AuthServiceBD
public AuthServiceBD()The constructor starts a connection to the Database and loads the list of users. Usesstart()andloadUsers()methods.
-
-
Method Details
-
registerNewUser
Registers a new user, and throws an exception if it is impossible.- Specified by:
registerNewUserin interfaceAuthService- Parameters:
nickName- Username..login- User login.pass- The user's password.- Returns:
- true if the registration was successful.
-
loadUsers
Loads all users from the Database to the list of users on the server.- Throws:
SQLException- при ошибке запроса.
-
start
public void start()Connects the connection to the Database, and creates a statement object.- Specified by:
startin interfaceAuthService
-
stop
public void stop()Closes the Database connection.- Specified by:
stopin interfaceAuthService
-
getNickByLoginPass
Returns the user's Name by his Username and Password.- Specified by:
getNickByLoginPassin interfaceAuthService- Parameters:
login- User login.pass- The user's password.- Returns:
- Username.
-
getMainHandlerList
-