|
|
|
|
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.
|
|

04-19-2008, 10:44 AM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 23
|
|
|
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
|
|

04-19-2008, 10:52 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 251
|
|
|
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
|
|

04-19-2008, 10:59 AM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 23
|
|
|
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?
|
|

04-19-2008, 11:16 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 251
|
|
|
Pal,
I just compiled your program onto console(Command Prompt) and It's working fine.
just try it at command prompt.
sanjeev
|
|

04-19-2008, 11:16 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by jon80
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:
-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)
|
|

04-19-2008, 02:31 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
|
Use JCreator....
regards,
sukatoa
|
|

04-19-2008, 10:36 PM
|
|
Member
|
|
Join Date: Apr 2008
Location: USA
Posts: 12
|
|
I would use the PasswordUtils if I were you:
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();
}
}
|
|

04-21-2008, 09:09 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by JavaLovenJoe
I would use the PasswordUtils if I were you:
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)
|
|

04-21-2008, 10:07 PM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 23
|
|
|
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)?
|
|

11-14-2008, 03:19 PM
|
|
Member
|
|
Join Date: Nov 2008
Posts: 5
|
|
|
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;
}
}
}
}
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
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