Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the code for this listed below but i have a few errors can i get help clearing up my errors in Java UserConnector.java

I have the code for this listed below but i have a few errors can i get help clearing up my errors in Java

UserConnector.java

package userCreation; import java.sql.*; public class UserConnector { private String firstname; private String lastname; private String username; private String password; private String permissions; public boolean Server_Error = false; public void setUserCreationData(String first, String last, String user, String pass){ firstname = first; lastname = last; username = user; password = pass; } public void UserLogData(String user, String pass){ username = user; password = pass; } public void setPermissions(String userPerm){ permissions = userPerm; } public String getPermissions(){ return permissions; } public String getUsername(){ return username; } public boolean UserCheckConnector() { boolean pass = false; Server_Error = false; try { Connection con = DriverManager.getConnection("jdk:mysql://localhost:3306/users", "UserCreator", "password"); Statement myStat = con.createStatement(); ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY UserName= '" + username + "';"); while(rs.next()){ if(rs.getString("Username") !=null){ pass = true; } } rs.close(); myStmt.close(); con.close(); } catch (SQLException exc){ System.out.println(exc); Server_Error = true; pass = true; } return pass; } public void UserCreationConnector() { Server_Error = false; try { Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "Usercreation", "password"); Statement myStmt = con.createStatement(); myStmt.executeUpdate("INSERT INFO app_users (Username, FirstName, LastName, Pass) VALUES ('" + username + "', " + firstname + "' , '" + lastname + "',MD5('" + password + "'));"); myStmt.close(); con.close(); } catch (SQLException exc) { System.out.println(exc); } } public boolean LoginConnector(){ boolean pass = false; Server_Error = false; try{ Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "app_control", "password"); Statement myStmt = con.createStatement(); ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY Username= '" + username + "' AND Pass=MD5('"+password+"'"); while ((rs.next())){ if(rs.getString(("Permissions") !=null){ pass=true; setPermissions(rs.getString("Permissions")); } } if(pass){ myStmt.executeUpdate("UPDATE app_users SET LastLogin=NOW() WHERE BINARY UserName= '" +username +"' AND PASS = MD5('"+password+"'"); } con.close(); myStmt.close(); rs.close(); } catch (SQLException exc){ System.out.println(exc); Server_Error = true; } return pass; } } 

Controller.java

package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text; @FXML private TextField Username_text; public Text UsedUsername_text; public Text ServerError_text; public Text NoMatchPass_text; public Text PatternError_text; public Text SubmitError_text; UserConnector userConnector = new UserConnector(); @FXML private void handleBacktoLog_ButtonAction(ActionEvent event) throws IOException{ System.out.println("Switch to login UI"); Parent newuser_ui = FXMLLoader.load(getClass().getResource("/inv_manager/LoginUIDocument.fxml")); Scene newuser_scene = new Scene(newuser_ui); Stage app_stage = (Stage) ((Node)event.getSource()).getScene().getWindow(); app_stage.setScene(newuser_scene); app_stage.show(); } @FXML private void handleSubmit_ButtonAction(ActionEvent event) throws IOException{ resetErrorMessage(); if(accoutFormCheck()){ if(Password_text.getText().equals(Confirm_text.getText())){ System.out.println("The Password match"); userConnector.setUserCreationData((FirstName_text.getText().substring(0,1).toUpperCase() + FirstName_text.getText().substring(1)) (LastName_text.getText().substring(0,1).toUpperCase() + LastName_text.getText().substring(1)) (UsedUsername_text.getText(), Password_text.getText()) if(!userConnector.UserCheckConnector() || !userConnector.Server_Error){ System.out.println("No matching username was found"); System.out.println("Creating new user now"); userConnector.UserCreationConnector(); }else{ if(userConnector.Server_Error){ ServerError_text.setVisible(true); }else{ System.out.println("A matching username was found"); Username_text.setVisible(true); } } }else { System.out.println("Passwords didn't match"); NoMatchPass_text.setVisible(true); } } else{ System.out.println("Pattern Error"); } } private boolean accoutFormCheck() { boolean pass = true; Pattern userpattern = Pattern.compile("^[a-zA-Z]{1}([a-zA-z0-9.]){4,11}$"); Pattern namepattern = Pattern.compile("^[a-zA-Z]{2,16}$"); Pattern passwordPattern = Pattern.compile("^(?=.*[0-9])(?=.*[a-z)(?=.*[A-Z])(?=.*[!@#$%^&+=])(?=\\S+$).{8,16}$"); Matcher matcher = namepattern.matcher((FirstName_text.getText())); if (!matcher.matches()) { pass = false; System.out.println("Firstname field was blank or didn't match a name pattern"); FirstName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red"); } else { FirstName_text.setStyle(null); } matcher = namepattern.matcher(LastName_text.getText()); if (!matcher.matches()) { pass = false; System.out.println("Lastname filed was blank or didn't match a name pattern"); LastName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;"); } else { LastName_text.setStyle(null); } matcher = userpattern.matcher((Username_text.getText())); if (!matcher.matches()) { pass = false; Username_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;"); System.out.println("Username field was blank or didn't match a username pattern"); } else { Username_text.setStyle(null); } matcher = passwordPattern.matcher((Password_text.getText())); if (!matcher.matches()) { pass = false; Password_text.setStyle(" -fx-text-box-border: red; -fx-focus-color: red;"); Confirm_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;"); System.out.println("Password field was blank or didn't match a password pattern"); PatternError_text.setVisible(true); } else { Password_text.setStyle(null); Confirm_text.setStyle(null); } if (!pass) SubmitError_text.setVisible(true); else SubmitError_text.setVisible(false); return pass; } private void resetErrorMessage() { ServerError_text.setVisible(false); NoMatchPass_text.setVisible(false); Username_text.setVisible(false); PatternError_text.setVisible(false); SubmitError_text.setVisible(false); } @Override public void initialize(URL url, ResourceBundle resourceBundle) { } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago