Results 1 to 10 of 10

Thread: password ?!

  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default 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 08:45 AM. Reason: update #1

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    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

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default 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?

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Pal,

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

    just try it at command prompt.

    sanjeev

  5. #5
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    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:

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

    :)
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Use JCreator....

    regards,
    sukatoa

  7. #7
    JavaLovenJoe is offline Member
    Join Date
    Apr 2008
    Location
    USA
    Posts
    12
    Rep Power
    0

    Default

    I would use the PasswordUtils if I were you:

    Java 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();
    	}
    }

  8. #8
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Quote Originally Posted by JavaLovenJoe View Post
    I would use the PasswordUtils if I were you:

    Java 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?
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  9. #9
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    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)?

  10. #10
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

    Default 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;
    }
    }




    }
    }

Similar Threads

  1. Password System help
    By quickfingers in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 06:18 PM
  2. Asking for password from a Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-27-2008, 08:05 PM
  3. add password to folder
    By ismailsaleh in forum AWT / Swing
    Replies: 1
    Last Post: 01-08-2008, 05:46 AM
  4. Problem with a password
    By saytri in forum New To Java
    Replies: 2
    Last Post: 12-27-2007, 11:06 AM
  5. Help with password matches
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-10-2007, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •