Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 26th, 2005, 10:37 AM   #1
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Registration Program[solved]

This Program Registers A User And Logs In The User Using The Same Username/Passowrd. It Also Creates A File To Save The Username And Password In. When I Log In As A Registered User, It Works Fine But When I Log In Before Registraing A User, It Gives Me An Error. I Know The Problem But Don't Know How To Fix It. Can Someone Help?

import java.awt.*;
import hsa.Console;
import java.io.*;

public class register
{
    static Console c = new Console ();
    static String entry = "", enter = "";
    static String enter1 = "";
    static char letter;
    static public void main (String[] args) throws IOException
    {
        String option1 = "", back = "";
        String email = "";

        String file[] = new String [2];
        PrintWriter save;
        BufferedReader saved;


        do
        {
            c.clear ();
            c.println ("Login/Registration System");
            c.println ();
            c.print (" 1) ");
            c.println ("Register");
            c.print (" 2) ");
            c.println ("Log In");
            c.println ();
            c.print ("What Do You Want To Do? ");
            option1 = c.readLine ();
            if (option1.equalsIgnoreCase ("Register") == true || option1.equals ("1") == true)
            {
                c.clear ();
                c.println ("Login/Registration System");
                c.println ();
                c.print ("Username: ");
                enter1 = c.readLine ();
                save = new PrintWriter (new FileWriter (enter1 + ".txt"));
                save.println (enter1);
                c.print ("Password: ");
                do
                {
                    letter = c.getChar ();
                    if ((int) letter >= 32 && (int) letter <= 126)
                    {
                        c.print ("*");
                        entry = entry + letter;
                    }


                    else if ((int) letter == 8 && entry.length () != 0)
                    {
                        c.setCursor (4, (12 + entry.length ()) - 1);
                        c.print (" ");
                        c.setCursor (4, 12 + entry.length () - 1);
                        if (entry.length () > 1)
                            entry = entry.substring (0, entry.length () - 1);
                        else
                            entry = "";
                    }
                }
                while ((int) letter != 10);
                save.println (entry);
                c.println ();
                c.print ("Email: ");
                email = c.readString ();
                save.println (email);
                save.close ();
                for (long b = 0 ; b <= 10000000 ; b++)
                    ;
                c.println ("Congratulations!! Your Registration Was A Success");
                c.print ("Go back? ");
                back = c.readString ();
            }
            if (option1.equalsIgnoreCase ("Log In") == true || option1.equalsIgnoreCase ("login") == true || option1.equals ("2") == true)
            {
                c.clear ();
                c.println ("Login/Registration System");
                c.println ();
                c.print ("Username: ");
                enter = c.readLine ();
                saved = new BufferedReader (new FileReader (enter + ".txt"));
                file [0] = saved.readLine ();
                c.print ("Connecting ");
                for (long a = 0 ; a <= 10000000 ; a++)
                    ;
                c.print (".");
                for (long a = 0 ; a <= 10000000 ; a++)
                    ;
                c.print (".");
                for (long a = 0 ; a <= 10000000 ; a++)
                    ;
                c.print (".");
                c.println (" Username Accepted");
                c.print ("Password: ");
                do
                {
                    letter = c.getChar ();
                    if ((int) letter >= 32 && (int) letter <= 126)
                    {
                        c.print ("*");
                        entry = entry + letter;
                    }


                    else if ((int) letter == 8 && entry.length () != 0)
                    {
                        c.setCursor (5, (12 + entry.length ()) - 1);
                        c.print (" ");
                        c.setCursor (5, 12 + entry.length () - 1);
                        if (entry.length () > 1)
                            entry = entry.substring (0, entry.length () - 1);
                        else
                            entry = "";
                    }
                }
                while ((int) letter != 10);
                file [1] = saved.readLine ();
                if (entry.equals (file [1]) == false)
                {
                    c.setCursor (6, 1);
                    c.println ("\t Invalid ... try again");
                }
                else
                {
                    c.println ();
                    c.print ("Connecting ");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    c.println (" Password Accepted");
                    c.println ();
                    c.print ("Connecting ");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    c.println (" Connection Established");
                    c.print ("Gaining Access ");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    c.println (" Access Granted");
                    c.println ();
                    c.print ("Logging In ");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    for (long a = 0 ; a <= 10000000 ; a++)
                        ;
                    c.print (".");
                    c.println (" Login Successful");
                    continue;
                }
            }
        }
        while (back.equalsIgnoreCase ("Yes"));
        c.clear ();
        c.print ("Login/Registration System");
        c.setTextColor (Color.gray);
        c.println ("\tUser CP");
        c.setTextColor (Color.black);
        c.println ();
        c.println ("Congratulations!! Your Login Was A Success");
    }
}

Last edited by Dark Flare Knight; Jun 4th, 2005 at 10:58 AM.
Dark Flare Knight is offline   Reply With Quote
Old May 26th, 2005, 10:41 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Load the users into an array at the start of the program, and use that array instead of checking the file at each login - that should fix it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 26th, 2005, 2:34 PM   #3
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Don't Know How To Do That Or I'm Just Not Thinking Hard Enough.
Dark Flare Knight is offline   Reply With Quote
Old May 27th, 2005, 2:37 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
Look up arrays and Switch in your nearest programming book....

http://java.sun.com/docs/books/tutor...ta/arrays.html
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old May 27th, 2005, 5:10 PM   #5
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Actually I Want To Read From The Files Rather Than Store It In The Array. If There Is Any Way To Store it in The Array and read files, i'd like to know how.

@Berto, how would checking how to use arrays and switch help me solve my problem?

Last edited by Dark Flare Knight; May 27th, 2005 at 5:14 PM.
Dark Flare Knight is offline   Reply With Quote
Old May 27th, 2005, 6:24 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Please, stop capitalising your every word. It's hideously annoying.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 28th, 2005, 3:18 PM   #7
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
My bad :o
Dark Flare Knight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC