![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
Don't Know How To Do That Or I'm Just Not Thinking Hard Enough.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
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 |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Please, stop capitalising your every word. It's hideously annoying.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
My bad :o
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|