Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-19-2008, 10:44 AM
Member
 
Join Date: Feb 2008
Posts: 23
jon80 is on a distinguished road
password ?!
import java.util.*;
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter username:");
String username = in.nextLine();

System.out.println("Enter your password:");
char[] passwd = System.console().readPassword();
// ERROR:
// Exception in thread "main" java.lang.NullPointerException
// at javaapplication2.Main.main(Main.java:26),




}

}

Last edited by jon80 : 04-19-2008 at 10:45 AM. Reason: update #1
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-19-2008, 10:52 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 251
sanjeevtarar is on a distinguished road
Hello,

There is no error in your program.....neither at compile time nor at run time...

Or you have not posted complete program..??
What is the problem or error ....

sanjeev
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 10:59 AM
Member
 
Join Date: Feb 2008
Posts: 23
jon80 is on a distinguished road
er...
Java does not seem to agree with that statement, any idea why?

I'm using NetBeans 6.0.1 on Java 1.6, what are you using pls?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 11:16 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 251
sanjeevtarar is on a distinguished road
Pal,

I just compiled your program onto console(Command Prompt) and It's working fine.

just try it at command prompt.

sanjeev
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 11:16 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by jon80 View Post
Java does not seem to agree with that statement, any idea why?

I'm using NetBeans 6.0.1 on Java 1.6, what are you using pls?
The problem is that when you're running it from Netbeans - it's not using a Console. If you're on Windows or Linux, use a terminal to run the program and it will work, the below is run from my Linux system's terminal:

Quote:
-bash-3.20$ java Main
Enter username:
hello
Enter your password:

-bash-3.20$
It asked me for the password and once it accepted it terminated the program normally.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 02:31 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Use JCreator....

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 10:36 PM
Member
 
Join Date: Apr 2008
Location: USA
Posts: 12
JavaLovenJoe is on a distinguished road
I would use the PasswordUtils if I were you:

Code:
import com.blogspot.joelnkode.tutorial.java.*; public class CoolCode extends NewApplication { public void startHere() { String username = new InputUtils("Enter your username:"); String password = new PasswordUtils("Enter your password:"); ApplicationUtils.exit(); } }
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-21-2008, 09:09 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by JavaLovenJoe View Post
I would use the PasswordUtils if I were you:

Code:
import com.blogspot.joelnkode.tutorial.java.*; public class CoolCode extends NewApplication { public void startHere() { String username = new InputUtils("Enter your username:"); String password = new PasswordUtils("Enter your password:"); ApplicationUtils.exit(); } }
Joe, your library use is not a standard- it's best to first start looking in the standard library's first- why use an external library if one is already provided for you in the default JDK?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-21-2008, 10:07 PM
Member
 
Join Date: Feb 2008
Posts: 23
jon80 is on a distinguished road
Actually the code posted did not compile either, the "simplistic" version of the working code follows:

<code>
import java.util.*;
public class Password {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter username:");
String username = in.nextLine();

System.out.println("Enter your password:");
char[] passwd = System.console().readPassword();

System.out.println("Username: " + username);
System.out.println("Password (encrypted): " + passwd.toString());
}
}
</code>

Any idea how the System.console.readPassword() method stores values (e.g. encryption standard)?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-14-2008, 03:19 PM
Member
 
Join Date: Nov 2008
Posts: 5
sk.mahaboobbhasha@gmail.c is on a distinguished road
how to verify the password with the databse password 3 times
hi

can any one help me in this.. i have a html/jsp form in that i have a field .. enter password... first time password will be stored in the databse... from second time when user enters passowrd wrongly for 3 times then it has to dispay some msg contact ur administrator. can any one send me this code? plzzzzzzzzzzzzzzzz send it ASAp

here is my code..

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Validation extends HttpServlet
{
private ServletConfig config;
public void init(ServletConfig config)throws ServletException
{
this.config=config;
}

public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
String userName = request.getParameter("user");
String password = request.getParameter("pass");
PrintWriter out =response.getWriter();
HttpSession session = request.getSession();

boolean login(String userName, String password)
{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost/basha","root","3ptec");
Statement s = con.createStatement();
String sql = "SELECT user FROM user" +
" WHERE user='" + user + "'" +
" AND Password='" + password + "'";
ResultSet rs = s.executeQuery(sql);
if (rs.next())
{
rs.close();
s.close();
con.close();
return true;
}
rs.close();
s.close();
con.close();
}

if(userName.equals(request.getParameter("user"))&& password.equals(request.getParameter("pass")))
{
out.println("<h1>User is Valid</h1>");
}
else
{
out.println("<h1>User is InValid</h1>");
}

if (!login(username, password) )
{
int count = Integer.parseInt( session.getAttribute("count") );
if (count > 3) {
response.sendRedirect("badbadUser.jsp");
}
else {
count++;
session.setAttribute("count");
response.sendRedirect("woopsWrongPasswordTryAgain. jsp");
}

catch (ClassNotFoundException e)
{
System.out.println(e.toString());
}
catch (SQLException e) {
System.out.println(e.toString());
}
catch (Exception e) {
System.out.println(e.toString());
}
return false;
}
}




}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password System help quickfingers New To Java 1 06-23-2008 08:18 PM
Asking for password from a Servlet Java Tip Java Tips 0 01-27-2008 10:05 PM
add password to folder ismailsaleh AWT / Swing 1 01-08-2008 07:46 AM
Problem with a password saytri New To Java 2 12-27-2007 01:06 PM
Help with password matches Albert AWT / Swing 1 07-10-2007 06:17 PM


All times are GMT +3. The time now is 11:45 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org