Authentication with java
Solved
supcomingénieur
Posted messages
87
Status
Membre
-
supcomingénieur Posted messages 87 Status Membre -
supcomingénieur Posted messages 87 Status Membre -
Hello,
I'm developing an authentication application with Java. I've already created the necessary graphical interface. But for it to be functional, tests and comparisons need to be made in an SQL database.
I've done this same application before with Java streams (FileReader, InputStream...). But this time I need to do it with a real database and not with text files.
Does anyone have the code? I was told it was quite simple. Unfortunately, this is my first experience with databases, so it's complicated for me.
Thank you very much.
I'm developing an authentication application with Java. I've already created the necessary graphical interface. But for it to be functional, tests and comparisons need to be made in an SQL database.
I've done this same application before with Java streams (FileReader, InputStream...). But this time I need to do it with a real database and not with text files.
Does anyone have the code? I was told it was quite simple. Unfortunately, this is my first experience with databases, so it's complicated for me.
Thank you very much.
15 réponses
Hello,
don't forget to instantiate the authentication object
Regards, Kafi
don't forget to instantiate the authentication object
public void actionPerformed(ActionEvent e) { login = field.getText(); pass = new String(fieldPass.getPassword()); if (authenticate(login, pass)) { //action to take if you are authenticated } } public class authentication { public authentication {} public authenticate(String login ,String pass) { String username = "root"; String password = "root"; String url = "jdbc:mysql://localhost/project"; try { //database connection Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection(url,username,password); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM USER"); while(resultSet.next()) { if ((login.equals(resultSet.getString("login"))==0) && (pass.equals(resultSet.getString("password"))==0)) ) { return true; } else{ return false;} } } catch (Exception e) { System.out.println("driver failure: "+e); } } } Regards, Kafi
Hello,
First of all, I need some information about your progress:
What code do you want?
- The code to create your SQL database and your table?
- The code to connect to your existing database (in this case specify the type of database used as well as your table).
Bonus question:
- Have you already installed your database server (which one?)
Best regards.
First of all, I need some information about your progress:
What code do you want?
- The code to create your SQL database and your table?
- The code to connect to your existing database (in this case specify the type of database used as well as your table).
Bonus question:
- Have you already installed your database server (which one?)
Best regards.
Yes, thank you for this code
I just have one question: is public authentificate(String login, String pass) a method or a constructor? Because you didn't specify the return type and that causes a blockage because of that.
I just have one question: is public authentificate(String login, String pass) a method or a constructor? Because you didn't specify the return type and that causes a blockage because of that.
```sql
CREATE TABLE utilisateur
(login varchar(32) NOT NULL,
password varchar(32),
PRIMARY KEY (login))
```
Ensuite côté java le code de kafiristanica devrait être OK.
CREATE TABLE utilisateur
(login varchar(32) NOT NULL,
password varchar(32),
PRIMARY KEY (login))
```
Ensuite côté java le code de kafiristanica devrait être OK.
Oh yes, sorry!!!
It's a method that returns a boolean
this allows to enter the condition of the actionPerformed of the connection button.
Best regards
It's a method that returns a boolean
this allows to enter the condition of the actionPerformed of the connection button.
Best regards
I have a problem again with the Kafiristanica code
it's the JDBC driver.
I have a class not found exception.
Thank you for enlightening me.
it's the JDBC driver.
I have a class not found exception.
Thank you for enlightening me.
Hi,
Not knowing which class is not found, I assume it's one related to JDBC.
You need to download the JDBC library for MySQL https://dev.mysql.com/downloads/connector/j/
You place the .jar in the classpath of your project.
Not knowing which class is not found, I assume it's one related to JDBC.
You need to download the JDBC library for MySQL https://dev.mysql.com/downloads/connector/j/
You place the .jar in the classpath of your project.
Hello,
I would like someone to explain to me how to add the JDBC driver in NetBeans. I've been trying to do it for two days and I can't manage it. As a result, it's preventing me from making progress on my project.
Another question: I don't know where to put the name of my database, so my URL is probably incorrect.
Thank you very much.
I would like someone to explain to me how to add the JDBC driver in NetBeans. I've been trying to do it for two days and I can't manage it. As a result, it's preventing me from making progress on my project.
Another question: I don't know where to put the name of my database, so my URL is probably incorrect.
Thank you very much.
The URL is of the type:
connection = DriverManager.getConnection("jdbc:mysql://host/database","user","password");
For Netbeans, you need to download the JDBC Connector, then add it to the project. Finally, under Eclipse it’s like this but it should be the same :-)
The wolf, solitary and mysterious.
connection = DriverManager.getConnection("jdbc:mysql://host/database","user","password");
For Netbeans, you need to download the JDBC Connector, then add it to the project. Finally, under Eclipse it’s like this but it should be the same :-)
The wolf, solitary and mysterious.
Hello,
here's my problem. I'm developing a strong authentication application in Java. It requires two elements:
what we know (password, etc.)
what we have (phone, smart card, etc.)
for the first element, I've developed a Java application that performs this authentication and allows or denies access to a user
as for the second element, I'm completely stuck. I don't know how to integrate this application on a phone, especially since I've programmed everything in Java
do you have any suggestions for fulfilling this second condition, that is, the part of what we have??
thank you
here's my problem. I'm developing a strong authentication application in Java. It requires two elements:
what we know (password, etc.)
what we have (phone, smart card, etc.)
for the first element, I've developed a Java application that performs this authentication and allows or denies access to a user
as for the second element, I'm completely stuck. I don't know how to integrate this application on a phone, especially since I've programmed everything in Java
do you have any suggestions for fulfilling this second condition, that is, the part of what we have??
thank you