• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

JDBC validating username and password against SQL database

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi People
I've got a problem: I need to create a database(SQL) to store username and passwords. I've made the database. Now I need to write a Login Screen(Java application) where users can input the username and password, the Java Application needs so verify that the username and password matches the respective entry in the database, if any.

This is what I've done:




The errors I'm getting says that my "Username did not match the database" and I'm sure that it should because it is the correct username


the usernames and passwords entered in my database are as follows:



Please tell me what I'm doing wrong
Thanks
Dene
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with



== for object types compares reference not the value.
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Purushothaman Thambu wrote:Try with



== for object types compares reference not the value.



Thank you Purushothaman is works great now, thank you for taking the time to help
Dene
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are building a secure database you should not be keeping the actual password in your database.
The password should be kept as an encrypted value and when the
user enters their password it is encrypted with the same algorithm
and compared to the database value.

Agad
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Agador Paloi wrote: If you are building a secure database you should not be keeping the actual password in your database.
The password should be kept as an encrypted value and when the
user enters their password it is encrypted with the same algorithm
and compared to the database value.

Agad



Hi Agad
It's sounds like the better thing to do, the problem is that i don't know how to do it. Is it something that I am supposed to do inside my SQL database or in my Java code?

In my Java code I have tried to change the password field to a JPasswordField but I get an error on this piece of code:


The message is:

Can you please tell me what I'm doing wrong and what I should do, or maybe a tutorial on how to fix it?

Thank you in advance
Dene
 
author & internet detective
Posts: 39760
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dene,
If you look at the String class JavaDoc, there should be something about converting a char[] to a String. I think it's one of the constructors.
 
Agador Paloi
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPassword does not do any encryption, it just doesnt display the entered field
on the screen. You could use something like MessageDigest to create
an encrypted password :

 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!