This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

JDBC validating username and password against SQL database

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 40847
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic