Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

AAAH! Debugging!!

DarknessXDarknessX Member Posts: 49
[b][red]This message was edited by DarknessX at 2007-2-7 19:46:55[/red][/b][hr]
[b][red]This message was edited by DarknessX at 2007-2-7 18:59:23[/red][/b][hr]
Ok, well, I'm mostly done my security program, only have a few things left to do, but right now, my program just WONT work for some reason.

Basically, it reads the userfile, it compares username/password/email, and it compares security code (first letter of user/pass/email) and logs you in. So before the if username = usercheck then... I put in some code, and it just isn't running properly.

[code]
Procedure Login;
begin
Writeln('Type your username.');
Readln(username);
if username = 'register' then begin ClrScr; RegisterX; end;
Writeln('Type your password.');
Readln(password);
Writeln('Type your e-mail.');
Readln(email);
confirmuser := Copy(username,1,1);
confirmpass := Copy(password,1,1);
confirmemail := Copy(email,1,1);
confirm := Concat(confirmuser,confirmpass,confirmemail);
assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
Reset(files);
Readln(Files,usercheck);
Readln(Files,passcheck);
Readln(Files,email);
Readln(Files,confirmcode);
Readln(Files,AuthCheck);
Close(files);
if username <> usercheck then begin
Counter := Counter+1;
Case Counter of
1 : begin
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
Logoff;
end;

2 : begin
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
Logoff;
end;

3 : begin
Counter := 1;
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
ShutDown;
end;
end;{End Case}
end;

if password <> passcheck then begin
Counter := Counter+1;
Case Counter of
1 : begin
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
Logoff;
end;

2 : begin
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
Logoff;
end;

3 : begin
Counter := 1;
Assign(files,'C:WindowsSecurity Centerfailed.txt');
Rewrite(files);
Writeln(Counter);
Close(files);
ShutDown;
end;
end; {End Case}
end;
if username = usercheck then begin
if password = passcheck then begin
Authorized := 'y';
usercheck := username;
username := '';
passcheck := password;
password := '';
ClrScr;
Writeln('Username: ',usercheck);
Writeln('Password: ',passcheck);
writeln('E-Mail: ',email);
writeln('Auth Level: ',authcheck);
Writeln('Authorized: ',authorized);
Readln;
ClrScr;
end;
end;


end;
[/code]
Any obvious mistakes? If you need the whole source, I uploaded it to RapidShare. Please, Please help me figure out why its not working.

Note: EVERYTHING the program uses is in C:WindowsSecurity Center

Security Center
Users
Commands
failed.txt

That's how it is setup.

Thanks for all help in advance.
http://rapidshare.com/files/15445531/Security.pas.html <-- the full source
NOTE: I know it's not a problem with my .bat files... They work fine if run through the menu.


Comments

  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by DarknessX at 2007-2-7 19:46:55[/red][/b][hr]
    : [b][red]This message was edited by DarknessX at 2007-2-7 18:59:23[/red][/b][hr]
    : Ok, well, I'm mostly done my security program, only have a few things left to do, but right now, my program just WONT work for some reason.
    :
    : Basically, it reads the userfile, it compares username/password/email, and it compares security code (first letter of user/pass/email) and logs you in. So before the if username = usercheck then... I put in some code, and it just isn't running properly.
    :
    : [code]
    : Procedure Login;
    : begin
    : Writeln('Type your username.');
    : Readln(username);
    : if username = 'register' then begin ClrScr; RegisterX; end;
    : Writeln('Type your password.');
    : Readln(password);
    : Writeln('Type your e-mail.');
    : Readln(email);
    : confirmuser := Copy(username,1,1);
    : confirmpass := Copy(password,1,1);
    : confirmemail := Copy(email,1,1);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : Reset(files);
    : Readln(Files,usercheck);
    : Readln(Files,passcheck);
    : Readln(Files,email);
    : Readln(Files,confirmcode);
    : Readln(Files,AuthCheck);
    : Close(files);
    : if username <> usercheck then begin
    : Counter := Counter+1;
    : Case Counter of
    : 1 : begin
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 2 : begin
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 3 : begin
    : Counter := 1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : ShutDown;
    : end;
    : end;{End Case}
    : end;
    :
    : if password <> passcheck then begin
    : Counter := Counter+1;
    : Case Counter of
    : 1 : begin
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 2 : begin
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 3 : begin
    : Counter := 1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : ShutDown;
    : end;
    : end; {End Case}
    : end;
    : if username = usercheck then begin
    : if password = passcheck then begin
    : Authorized := 'y';
    : usercheck := username;
    : username := '';
    : passcheck := password;
    : password := '';
    : ClrScr;
    : Writeln('Username: ',usercheck);
    : Writeln('Password: ',passcheck);
    : writeln('E-Mail: ',email);
    : writeln('Auth Level: ',authcheck);
    : Writeln('Authorized: ',authorized);
    : Readln;
    : ClrScr;
    : end;
    : end;
    :
    :
    : end;
    : [/code]
    : Any obvious mistakes? If you need the whole source, I uploaded it to RapidShare. Please, Please help me figure out why its not working.
    :
    : Note: EVERYTHING the program uses is in C:WindowsSecurity Center
    :
    : Security Center
    : Users
    : Commands
    : failed.txt
    :
    : That's how it is setup.
    :
    : Thanks for all help in advance.
    : http://rapidshare.com/files/15445531/Security.pas.html <-- the full source
    : NOTE: I know it's not a problem with my .bat files... They work fine if run through the menu.
    :
    :
    :
    You should have used indentation in your code, because now it is hardly readable.
  • DarknessXDarknessX Member Posts: 49
    [b][red]This message was edited by DarknessX at 2007-2-8 17:58:26[/red][/b][hr]
    [b][red]This message was edited by DarknessX at 2007-2-8 17:55:11[/red][/b][hr]
    [b][red]This message was edited by DarknessX at 2007-2-8 17:54:45[/red][/b][hr]
    [b][red]This message was edited by DarknessX at 2007-2-8 17:4:23[/red][/b][hr]
    OK, I'm indenting it right now. It's only 400 lines, only about a half hour-hour worth of work. I'll post the indented code after.


    EDIT: Heres the registration and login code:
    [code]
    Procedure Login;
    begin
    Writeln('Type your username.');
    Readln(username);
    if username = 'register' then begin ClrScr; RegisterX; end;
    Writeln('Type your password.');
    Readln(password);
    Writeln('Type your e-mail.');
    Readln(email);
    confirmuser := Copy(username,1,1);
    confirmpass := Copy(password,1,1);
    confirmemail := Copy(email,1,1);
    confirm := Concat(confirmuser,confirmpass,confirmemail);
    assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    Reset(files);
    Readln(Files,usercheck);
    Readln(Files,passcheck);
    Readln(Files,email);
    Readln(Files,confirmcode);
    Readln(Files,AuthCheck);
    Close(files);
    if username = usercheck then begin
    if password = passcheck then begin
    Authorized := 'y';
    usercheck := username;
    username := '';
    passcheck := password;
    password := '';
    ClrScr;
    Writeln('Username: ',usercheck);
    Writeln('Password: ',passcheck);
    writeln('E-Mail: ',email);
    writeln('Auth Level: ',authcheck);
    Writeln('Authorized: ',authorized);
    Readln;
    ClrScr;
    end;
    end;
    if username <> usercheck then begin
    Case Counter of
    2 : begin
    Counter := Counter+1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    Logoff;
    end;

    3 : begin
    Counter := Counter+1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    Logoff;
    end;

    4 : begin
    Counter := 1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    ShutDown;
    end;
    end;{End Case}
    end;

    if password <> passcheck then begin
    Case Counter of
    2 : begin
    Counter := Counter+1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    Logoff;
    end;

    3 : begin
    Counter := Counter+1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    Logoff;
    end;

    4 : begin
    Counter := 1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    ShutDown;
    end;
    end; {End Case}
    end;
    end;

    Procedure RegisterX;
    begin
    Writeln('Type a username.');
    readln(username);
    Writeln('Type a password.');
    readln(password);
    Writeln('Confirm Password.');
    readln(passcheck);
    Writeln('Type your e-mail.');
    readln(email);
    Writeln('Type your confirmation code.');
    readln(confirmcode);
    Writeln('Code?');
    Readln(authcheck);
    confirmuser := Copy(username,1,1);
    confirmpass := Copy(password,1,1);
    confirmemail := Copy(email,1,1);
    writeln(confirmuser, confirmpass, confirmemail);
    confirm := Concat(confirmuser,confirmpass,confirmemail);
    if confirmcode = confirm then begin {writing file}
    Writeln('Saving to file..');
    assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    Rewrite(files);
    Writeln(files,username);
    Writeln(files,password);
    Writeln(files,email);
    Writeln(files,confirm);
    Writeln(files,AuthCheck);
    Writeln(files,'DXSECURITY USERCODE');
    Close(files);
    end else begin
    Counter := Counter+1;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    if counter < 3 then logoff else begin
    Counter := 0;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Rewrite(files);
    Writeln(Counter);
    Close(files);
    Shutdown;
    end; {End writing file}
    end;
    ClrScr;
    Writeln('Closing..');
    Delay(400);
    Halt;
    end;
    [/code]
    It's a bit long, but you shouldn't need anything more.
    All help is appreciated.



  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by DarknessX at 2007-2-8 17:58:26[/red][/b][hr]
    : [b][red]This message was edited by DarknessX at 2007-2-8 17:55:11[/red][/b][hr]
    : [b][red]This message was edited by DarknessX at 2007-2-8 17:54:45[/red][/b][hr]
    : [b][red]This message was edited by DarknessX at 2007-2-8 17:4:23[/red][/b][hr]
    : OK, I'm indenting it right now. It's only 400 lines, only about a half hour-hour worth of work. I'll post the indented code after.
    :
    :
    : EDIT: Heres the registration and login code:
    : [code]
    : Procedure Login;
    : begin
    : Writeln('Type your username.');
    : Readln(username);
    : if username = 'register' then begin ClrScr; RegisterX; end;
    : Writeln('Type your password.');
    : Readln(password);
    : Writeln('Type your e-mail.');
    : Readln(email);
    : confirmuser := Copy(username,1,1);
    : confirmpass := Copy(password,1,1);
    : confirmemail := Copy(email,1,1);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : Reset(files);
    : Readln(Files,usercheck);
    : Readln(Files,passcheck);
    : Readln(Files,email);
    : Readln(Files,confirmcode);
    : Readln(Files,AuthCheck);
    : Close(files);
    : if username = usercheck then begin
    : if password = passcheck then begin
    : Authorized := 'y';
    : usercheck := username;
    : username := '';
    : passcheck := password;
    : password := '';
    : ClrScr;
    : Writeln('Username: ',usercheck);
    : Writeln('Password: ',passcheck);
    : writeln('E-Mail: ',email);
    : writeln('Auth Level: ',authcheck);
    : Writeln('Authorized: ',authorized);
    : Readln;
    : ClrScr;
    : end;
    : end;
    : if username <> usercheck then begin
    : Case Counter of
    : 2 : begin
    : Counter := Counter+1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 3 : begin
    : Counter := Counter+1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 4 : begin
    : Counter := 1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : ShutDown;
    : end;
    : end;{End Case}
    : end;
    :
    : if password <> passcheck then begin
    : Case Counter of
    : 2 : begin
    : Counter := Counter+1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 3 : begin
    : Counter := Counter+1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Logoff;
    : end;
    :
    : 4 : begin
    : Counter := 1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : ShutDown;
    : end;
    : end; {End Case}
    : end;
    : end;
    :
    : Procedure RegisterX;
    : begin
    : Writeln('Type a username.');
    : readln(username);
    : Writeln('Type a password.');
    : readln(password);
    : Writeln('Confirm Password.');
    : readln(passcheck);
    : Writeln('Type your e-mail.');
    : readln(email);
    : Writeln('Type your confirmation code.');
    : readln(confirmcode);
    : Writeln('Code?');
    : Readln(authcheck);
    : confirmuser := Copy(username,1,1);
    : confirmpass := Copy(password,1,1);
    : confirmemail := Copy(email,1,1);
    : writeln(confirmuser, confirmpass, confirmemail);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : if confirmcode = confirm then begin {writing file}
    : Writeln('Saving to file..');
    : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : Rewrite(files);
    : Writeln(files,username);
    : Writeln(files,password);
    : Writeln(files,email);
    : Writeln(files,confirm);
    : Writeln(files,AuthCheck);
    : Writeln(files,'DXSECURITY USERCODE');
    : Close(files);
    : end else begin
    : Counter := Counter+1;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : if counter < 3 then logoff else begin
    : Counter := 0;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Rewrite(files);
    : Writeln(Counter);
    : Close(files);
    : Shutdown;
    : end; {End writing file}
    : end;
    : ClrScr;
    : Writeln('Closing..');
    : Delay(400);
    : Halt;
    : end;
    : [/code]
    : It's a bit long, but you shouldn't need anything more.
    : All help is appreciated.
    :
    :
    :
    :
    Indenting should be done with 2 spaces. I noticed you never read the counter from the failed file. Neither are you resetting the Counter back to zero after a successful login.
  • DarknessXDarknessX Member Posts: 49
    : : [b][red]This message was edited by DarknessX at 2007-2-8 17:58:26[/red][/b][hr]
    : : [b][red]This message was edited by DarknessX at 2007-2-8 17:55:11[/red][/b][hr]
    : : [b][red]This message was edited by DarknessX at 2007-2-8 17:54:45[/red][/b][hr]
    : : [b][red]This message was edited by DarknessX at 2007-2-8 17:4:23[/red][/b][hr]
    : : OK, I'm indenting it right now. It's only 400 lines, only about a half hour-hour worth of work. I'll post the indented code after.
    : :
    : :
    : : EDIT: Heres the registration and login code:
    : : [code]
    : : Procedure Login;
    : : begin
    : : Writeln('Type your username.');
    : : Readln(username);
    : : if username = 'register' then begin ClrScr; RegisterX; end;
    : : Writeln('Type your password.');
    : : Readln(password);
    : : Writeln('Type your e-mail.');
    : : Readln(email);
    : : confirmuser := Copy(username,1,1);
    : : confirmpass := Copy(password,1,1);
    : : confirmemail := Copy(email,1,1);
    : : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : : Reset(files);
    : : Readln(Files,usercheck);
    : : Readln(Files,passcheck);
    : : Readln(Files,email);
    : : Readln(Files,confirmcode);
    : : Readln(Files,AuthCheck);
    : : Close(files);
    : : if username = usercheck then begin
    : : if password = passcheck then begin
    : : Authorized := 'y';
    : : usercheck := username;
    : : username := '';
    : : passcheck := password;
    : : password := '';
    : : ClrScr;
    : : Writeln('Username: ',usercheck);
    : : Writeln('Password: ',passcheck);
    : : writeln('E-Mail: ',email);
    : : writeln('Auth Level: ',authcheck);
    : : Writeln('Authorized: ',authorized);
    : : Readln;
    : : ClrScr;
    : : end;
    : : end;
    : : if username <> usercheck then begin
    : : Case Counter of
    : : 2 : begin
    : : Counter := Counter+1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : Logoff;
    : : end;
    : :
    : : 3 : begin
    : : Counter := Counter+1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : Logoff;
    : : end;
    : :
    : : 4 : begin
    : : Counter := 1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : ShutDown;
    : : end;
    : : end;{End Case}
    : : end;
    : :
    : : if password <> passcheck then begin
    : : Case Counter of
    : : 2 : begin
    : : Counter := Counter+1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : Logoff;
    : : end;
    : :
    : : 3 : begin
    : : Counter := Counter+1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : Logoff;
    : : end;
    : :
    : : 4 : begin
    : : Counter := 1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : ShutDown;
    : : end;
    : : end; {End Case}
    : : end;
    : : end;
    : :
    : : Procedure RegisterX;
    : : begin
    : : Writeln('Type a username.');
    : : readln(username);
    : : Writeln('Type a password.');
    : : readln(password);
    : : Writeln('Confirm Password.');
    : : readln(passcheck);
    : : Writeln('Type your e-mail.');
    : : readln(email);
    : : Writeln('Type your confirmation code.');
    : : readln(confirmcode);
    : : Writeln('Code?');
    : : Readln(authcheck);
    : : confirmuser := Copy(username,1,1);
    : : confirmpass := Copy(password,1,1);
    : : confirmemail := Copy(email,1,1);
    : : writeln(confirmuser, confirmpass, confirmemail);
    : : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : : if confirmcode = confirm then begin {writing file}
    : : Writeln('Saving to file..');
    : : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : : Rewrite(files);
    : : Writeln(files,username);
    : : Writeln(files,password);
    : : Writeln(files,email);
    : : Writeln(files,confirm);
    : : Writeln(files,AuthCheck);
    : : Writeln(files,'DXSECURITY USERCODE');
    : : Close(files);
    : : end else begin
    : : Counter := Counter+1;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : if counter < 3 then logoff else begin
    : : Counter := 0;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Rewrite(files);
    : : Writeln(Counter);
    : : Close(files);
    : : Shutdown;
    : : end; {End writing file}
    : : end;
    : : ClrScr;
    : : Writeln('Closing..');
    : : Delay(400);
    : : Halt;
    : : end;
    : : [/code]
    : : It's a bit long, but you shouldn't need anything more.
    : : All help is appreciated.
    : :
    : :
    : :
    : :
    : Indenting should be done with 2 spaces. I noticed you never read the counter from the failed file. Neither are you resetting the Counter back to zero after a successful login.
    :

    Oh, sorry. Ah, ok. That would probably be the problem with not reading the counter.. Thanks. I'll try and fix that again tonight.
  • DarknessXDarknessX Member Posts: 49
    [b][red]This message was edited by DarknessX at 2007-2-9 22:14:31[/red][/b][hr]
    GAH! I've changed my code severely, and yet it's still not working. Sorry if it's not indented properly, I've been too focused on making this work.
    I figured out ONE problem, which is if the file is not found to load from, it gives an error and halts. So I made a workaround...
    [code]
    Function IsValidUser;
    begin
    truefalse := false;
    Assign(files,'C:WindowsSecurity CenterUsersuserlist.txt');
    Reset(files);
    While s <> confirm do begin
    Repeat
    Readln(Files,s);
    if s = confirm then truefalse := true;
    Until Eof(Files);
    end;
    Close(files);
    end;

    Procedure CheckLogin;
    begin
    authorized := 'n';
    if username = usercheck then begin
    if password = passcheck then begin
    authorized := 'y';
    Writeln('Username: ',usercheck);
    Writeln('Password: ',passcheck);
    Writeln('E-Mail: ',email);
    Writeln('Auth Level: ',authcheck);
    end;
    end;
    if authorized <> 'y' then begin
    Writeln('Username/Password Incorrect...');
    s := '';
    swapvectors;
    exec('C:WindowsSecurity CenterCommandsgettime.bat',s);
    swapvectors;
    Assign(files,'C:WindowsSecurity CenterCommands ime.txt');
    reset(files);
    readln(files,time);
    close(files);
    Assign(files,'C:WindowsSecurity Centerlogs.txt');
    Append(files);
    Writeln('Failed Login on ',time,' by ',username,' with password ',password);
    Logoff;
    end;
    end;

    Procedure Login;
    begin
    Writeln('Type your username.');
    Readln(username);
    if username = 'register' then begin ClrScr; RegisterX; end;
    Writeln('Type your password.');
    Readln(password);
    Writeln('Type your e-mail.');
    Readln(email);
    confirmuser := Copy(username,1,1);
    confirmpass := Copy(password,1,1);
    confirmemail := Copy(email,1,1);
    confirm := Concat(confirmuser,confirmpass,confirmemail);
    IsValidUser;

    if truefalse = true then begin
    assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    Reset(files);
    Readln(Files,usercheck);
    Readln(Files,passcheck);
    Readln(Files,email);
    Readln(Files,confirmcode);
    Readln(Files,AuthCheck);
    Close(files);
    CheckLogin;
    end;
    end;

    Procedure RegisterX;
    begin
    Writeln('Type a username.');
    readln(username);
    Writeln('Type a password.');
    readln(password);
    Writeln('Confirm Password.');
    readln(passcheck);
    Writeln('Type your e-mail.');
    readln(email);
    Writeln('Type your confirmation code.');
    readln(confirmcode);
    Writeln('Code?');
    Readln(authcheck);
    confirmuser := Copy(username,1,1);
    confirmpass := Copy(password,1,1);
    confirmemail := Copy(email,1,1);
    writeln(confirmuser, confirmpass, confirmemail);
    confirm := Concat(confirmuser,confirmpass,confirmemail);
    if confirmcode = confirm then begin
    Writeln('Saving to file..');
    assign(files,'C:WINDOWSSecurity CenterUsersuserlist.txt');
    append(files);
    writeln(files,confirmcode);
    close(files);
    assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    rewrite(files);
    Writeln(files,username);
    Writeln(files,password);
    Writeln(files,email);
    Writeln(files,confirm);
    Writeln(files,AuthCheck);
    Writeln(files,'DXSECURITY USERCODE');
    Close(files);
    end;
    ClrScr;
    Writeln('Closing..');
    Delay(400);
    Halt;
    end;

    {BUNCH OF CODE NOT RELATED (IE, COMMAND RUNNING PROCEDURES)}

    begin
    JumpBack : ClrScr;
    Loading;
    Assign(files,'C:WindowsSecurity Centerfailed.txt');
    Reset(files);
    Readln(Files,Counter);
    Close(files);
    Login;
    textcolor(white);
    if authorized = 'y' then begin
    Writeln('Please confirm your confirm code.');
    Readln(confirmcode);
    confirmuser := Copy(usercheck,1,1);
    confirmpass := Copy(passcheck,1,1);
    confirmemail := Copy(email,1,1);
    confirm := Concat(confirmuser,confirmpass,confirmemail);
    if confirmcode = confirm then begin
    ClrScr;
    Commands;
    end {end if confirmcode = confirm then else} else Writeln('Sorry, incorrect confirm code.');
    end {end if authorized then else} else begin Writeln('Sorry, not authorized, switching to log in.'); Login; GOTO Jumpback; end;
    end.
    [/code]

    Sorry about the lack of comments. It won't login because of an error in the IsValidUser function, I've pinpointed it down to that, because if I comment out the IsValidUser function calls and truefalse to true it will login no problem.

    Aside from that, if you enter the wrong information, it gives an error that I can't catch.. I'm fairly sure it's because the file its trying to read does not exist in the checklogin procedure. I could be wrong; but that's what I think.

    Any help is appreciated...
  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by DarknessX at 2007-2-9 22:14:31[/red][/b][hr]
    : GAH! I've changed my code severely, and yet it's still not working. Sorry if it's not indented properly, I've been too focused on making this work.
    : I figured out ONE problem, which is if the file is not found to load from, it gives an error and halts. So I made a workaround...
    : [code]
    : Function IsValidUser;
    : begin
    : truefalse := false;
    : Assign(files,'C:WindowsSecurity CenterUsersuserlist.txt');
    : Reset(files);
    : While s <> confirm do begin
    : Repeat
    : Readln(Files,s);
    : if s = confirm then truefalse := true;
    : Until Eof(Files);
    : end;
    : Close(files);
    : end;
    :
    : Procedure CheckLogin;
    : begin
    : authorized := 'n';
    : if username = usercheck then begin
    : if password = passcheck then begin
    : authorized := 'y';
    : Writeln('Username: ',usercheck);
    : Writeln('Password: ',passcheck);
    : Writeln('E-Mail: ',email);
    : Writeln('Auth Level: ',authcheck);
    : end;
    : end;
    : if authorized <> 'y' then begin
    : Writeln('Username/Password Incorrect...');
    : s := '';
    : swapvectors;
    : exec('C:WindowsSecurity CenterCommandsgettime.bat',s);
    : swapvectors;
    : Assign(files,'C:WindowsSecurity CenterCommands ime.txt');
    : reset(files);
    : readln(files,time);
    : close(files);
    : Assign(files,'C:WindowsSecurity Centerlogs.txt');
    : Append(files);
    : Writeln('Failed Login on ',time,' by ',username,' with password ',password);
    : Logoff;
    : end;
    : end;
    :
    : Procedure Login;
    : begin
    : Writeln('Type your username.');
    : Readln(username);
    : if username = 'register' then begin ClrScr; RegisterX; end;
    : Writeln('Type your password.');
    : Readln(password);
    : Writeln('Type your e-mail.');
    : Readln(email);
    : confirmuser := Copy(username,1,1);
    : confirmpass := Copy(password,1,1);
    : confirmemail := Copy(email,1,1);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : IsValidUser;
    :
    : if truefalse = true then begin
    : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : Reset(files);
    : Readln(Files,usercheck);
    : Readln(Files,passcheck);
    : Readln(Files,email);
    : Readln(Files,confirmcode);
    : Readln(Files,AuthCheck);
    : Close(files);
    : CheckLogin;
    : end;
    : end;
    :
    : Procedure RegisterX;
    : begin
    : Writeln('Type a username.');
    : readln(username);
    : Writeln('Type a password.');
    : readln(password);
    : Writeln('Confirm Password.');
    : readln(passcheck);
    : Writeln('Type your e-mail.');
    : readln(email);
    : Writeln('Type your confirmation code.');
    : readln(confirmcode);
    : Writeln('Code?');
    : Readln(authcheck);
    : confirmuser := Copy(username,1,1);
    : confirmpass := Copy(password,1,1);
    : confirmemail := Copy(email,1,1);
    : writeln(confirmuser, confirmpass, confirmemail);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : if confirmcode = confirm then begin
    : Writeln('Saving to file..');
    : assign(files,'C:WINDOWSSecurity CenterUsersuserlist.txt');
    : append(files);
    : writeln(files,confirmcode);
    : close(files);
    : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : rewrite(files);
    : Writeln(files,username);
    : Writeln(files,password);
    : Writeln(files,email);
    : Writeln(files,confirm);
    : Writeln(files,AuthCheck);
    : Writeln(files,'DXSECURITY USERCODE');
    : Close(files);
    : end;
    : ClrScr;
    : Writeln('Closing..');
    : Delay(400);
    : Halt;
    : end;
    :
    : {BUNCH OF CODE NOT RELATED (IE, COMMAND RUNNING PROCEDURES)}
    :
    : begin
    : JumpBack : ClrScr;
    : Loading;
    : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : Reset(files);
    : Readln(Files,Counter);
    : Close(files);
    : Login;
    : textcolor(white);
    : if authorized = 'y' then begin
    : Writeln('Please confirm your confirm code.');
    : Readln(confirmcode);
    : confirmuser := Copy(usercheck,1,1);
    : confirmpass := Copy(passcheck,1,1);
    : confirmemail := Copy(email,1,1);
    : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : if confirmcode = confirm then begin
    : ClrScr;
    : Commands;
    : end {end if confirmcode = confirm then else} else Writeln('Sorry, incorrect confirm code.');
    : end {end if authorized then else} else begin Writeln('Sorry, not authorized, switching to log in.'); Login; GOTO Jumpback; end;
    : end.
    : [/code]
    :
    : Sorry about the lack of comments. It won't login because of an error in the IsValidUser function, I've pinpointed it down to that, because if I comment out the IsValidUser function calls and truefalse to true it will login no problem.
    :
    : Aside from that, if you enter the wrong information, it gives an error that I can't catch.. I'm fairly sure it's because the file its trying to read does not exist in the checklogin procedure. I could be wrong; but that's what I think.
    :
    : Any help is appreciated...
    :
    Your code looks way too complex. For example: why call an external file to get the time instead of GetTime()?
    Here's a better way to check if the user is valid:
    [code]
    function IsValidUser(UserName: string): boolean;
    var
    s: string;
    FoundUser: boolean;
    f: text;
    begin
    FoundUser := false;
    Assign(f,'C:WindowsSecurity CenterUsersuserlist.txt');
    Reset(f);
    while not eof(f) do
    begin
    Readln(f, s);
    if s = UserName then
    FoundUser := true;
    end;
    Close(files);
    IsValidUser := FoundUser;
    end;
    [/code]
    As you can see, it is a simple loop and a single if-then statement. Also it is better to use local variables instead of global ones. Global variables might produce security holes, or worse instabilities in your program.
  • DarknessXDarknessX Member Posts: 49
    : : [b][red]This message was edited by DarknessX at 2007-2-9 22:14:31[/red][/b][hr]
    : : GAH! I've changed my code severely, and yet it's still not working. Sorry if it's not indented properly, I've been too focused on making this work.
    : : I figured out ONE problem, which is if the file is not found to load from, it gives an error and halts. So I made a workaround...
    : : [code]
    : : Function IsValidUser;
    : : begin
    : : truefalse := false;
    : : Assign(files,'C:WindowsSecurity CenterUsersuserlist.txt');
    : : Reset(files);
    : : While s <> confirm do begin
    : : Repeat
    : : Readln(Files,s);
    : : if s = confirm then truefalse := true;
    : : Until Eof(Files);
    : : end;
    : : Close(files);
    : : end;
    : :
    : : Procedure CheckLogin;
    : : begin
    : : authorized := 'n';
    : : if username = usercheck then begin
    : : if password = passcheck then begin
    : : authorized := 'y';
    : : Writeln('Username: ',usercheck);
    : : Writeln('Password: ',passcheck);
    : : Writeln('E-Mail: ',email);
    : : Writeln('Auth Level: ',authcheck);
    : : end;
    : : end;
    : : if authorized <> 'y' then begin
    : : Writeln('Username/Password Incorrect...');
    : : s := '';
    : : swapvectors;
    : : exec('C:WindowsSecurity CenterCommandsgettime.bat',s);
    : : swapvectors;
    : : Assign(files,'C:WindowsSecurity CenterCommands ime.txt');
    : : reset(files);
    : : readln(files,time);
    : : close(files);
    : : Assign(files,'C:WindowsSecurity Centerlogs.txt');
    : : Append(files);
    : : Writeln('Failed Login on ',time,' by ',username,' with password ',password);
    : : Logoff;
    : : end;
    : : end;
    : :
    : : Procedure Login;
    : : begin
    : : Writeln('Type your username.');
    : : Readln(username);
    : : if username = 'register' then begin ClrScr; RegisterX; end;
    : : Writeln('Type your password.');
    : : Readln(password);
    : : Writeln('Type your e-mail.');
    : : Readln(email);
    : : confirmuser := Copy(username,1,1);
    : : confirmpass := Copy(password,1,1);
    : : confirmemail := Copy(email,1,1);
    : : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : : IsValidUser;
    : :
    : : if truefalse = true then begin
    : : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : : Reset(files);
    : : Readln(Files,usercheck);
    : : Readln(Files,passcheck);
    : : Readln(Files,email);
    : : Readln(Files,confirmcode);
    : : Readln(Files,AuthCheck);
    : : Close(files);
    : : CheckLogin;
    : : end;
    : : end;
    : :
    : : Procedure RegisterX;
    : : begin
    : : Writeln('Type a username.');
    : : readln(username);
    : : Writeln('Type a password.');
    : : readln(password);
    : : Writeln('Confirm Password.');
    : : readln(passcheck);
    : : Writeln('Type your e-mail.');
    : : readln(email);
    : : Writeln('Type your confirmation code.');
    : : readln(confirmcode);
    : : Writeln('Code?');
    : : Readln(authcheck);
    : : confirmuser := Copy(username,1,1);
    : : confirmpass := Copy(password,1,1);
    : : confirmemail := Copy(email,1,1);
    : : writeln(confirmuser, confirmpass, confirmemail);
    : : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : : if confirmcode = confirm then begin
    : : Writeln('Saving to file..');
    : : assign(files,'C:WINDOWSSecurity CenterUsersuserlist.txt');
    : : append(files);
    : : writeln(files,confirmcode);
    : : close(files);
    : : assign(files,'C:WindowsSecurity CenterUsers'+confirm+'.txt');
    : : rewrite(files);
    : : Writeln(files,username);
    : : Writeln(files,password);
    : : Writeln(files,email);
    : : Writeln(files,confirm);
    : : Writeln(files,AuthCheck);
    : : Writeln(files,'DXSECURITY USERCODE');
    : : Close(files);
    : : end;
    : : ClrScr;
    : : Writeln('Closing..');
    : : Delay(400);
    : : Halt;
    : : end;
    : :
    : : {BUNCH OF CODE NOT RELATED (IE, COMMAND RUNNING PROCEDURES)}
    : :
    : : begin
    : : JumpBack : ClrScr;
    : : Loading;
    : : Assign(files,'C:WindowsSecurity Centerfailed.txt');
    : : Reset(files);
    : : Readln(Files,Counter);
    : : Close(files);
    : : Login;
    : : textcolor(white);
    : : if authorized = 'y' then begin
    : : Writeln('Please confirm your confirm code.');
    : : Readln(confirmcode);
    : : confirmuser := Copy(usercheck,1,1);
    : : confirmpass := Copy(passcheck,1,1);
    : : confirmemail := Copy(email,1,1);
    : : confirm := Concat(confirmuser,confirmpass,confirmemail);
    : : if confirmcode = confirm then begin
    : : ClrScr;
    : : Commands;
    : : end {end if confirmcode = confirm then else} else Writeln('Sorry, incorrect confirm code.');
    : : end {end if authorized then else} else begin Writeln('Sorry, not authorized, switching to log in.'); Login; GOTO Jumpback; end;
    : : end.
    : : [/code]
    : :
    : : Sorry about the lack of comments. It won't login because of an error in the IsValidUser function, I've pinpointed it down to that, because if I comment out the IsValidUser function calls and truefalse to true it will login no problem.
    : :
    : : Aside from that, if you enter the wrong information, it gives an error that I can't catch.. I'm fairly sure it's because the file its trying to read does not exist in the checklogin procedure. I could be wrong; but that's what I think.
    : :
    : : Any help is appreciated...
    : :
    : Your code looks way too complex. For example: why call an external file to get the time instead of GetTime()?
    : Here's a better way to check if the user is valid:
    : [code]
    : function IsValidUser(UserName: string): boolean;
    : var
    : s: string;
    : FoundUser: boolean;
    : f: text;
    : begin
    : FoundUser := false;
    : Assign(f,'C:WindowsSecurity CenterUsersuserlist.txt');
    : Reset(f);
    : while not eof(f) do
    : begin
    : Readln(f, s);
    : if s = UserName then
    : FoundUser := true;
    : end;
    : Close(files);
    : IsValidUser := FoundUser;
    : end;
    : [/code]
    : As you can see, it is a simple loop and a single if-then statement. Also it is better to use local variables instead of global ones. Global variables might produce security holes, or worse instabilities in your program.
    :

    OK, Thanks Zibadian. I will go try that out right now and hopefully it will work. I wasn't sure how to use the GetTime(); function, I attempted it, but I couldn't get the syntax right. However, I thank you for the help with the login check.
  • DarknessXDarknessX Member Posts: 49
    It's working! Thanks, Zibadian. I modified your code a little bit to suite my program, since I didn't understand it 100%, but I kept the basics, and now it works! My program is about 89% complete, so I'll post a download here when I get it all working and setup. Thanks again!
  • zibadianzibadian Member Posts: 6,349
    : It's working! Thanks, Zibadian. I modified your code a little bit to suite my program, since I didn't understand it 100%, but I kept the basics, and now it works! My program is about 89% complete, so I'll post a download here when I get it all working and setup. Thanks again!
    :
    [code]
    function IsValidUser(UserName: string): boolean;
    var
    s: string;
    FoundUser: boolean;
    f: text;
    begin
    FoundUser := false; { Assume username is not listed in the file }
    Assign(f,'C:WindowsSecurity CenterUsersuserlist.txt');
    Reset(f); { Open the file }
    [/code]
    Next you need to read each line in the file. This is best done using a while-do loop, since it first checks if the end-of-file is reached before performing the read:
    [code]
    while not eof(f) do
    begin
    Readln(f, s);
    end;
    [/code]
    Once you have read a line, then check if that line lists the username you want to check (UserName parameter):
    [code]
    if s = UserName then
    [/code]
    If it does you store the result in the correct variable:
    [code]
    if s = UserName then
    FoundUser := true;
    [/code]
    After the whole file has been read, close it and return the result to the caller of the function:
    [code]
    Close(files);
    IsValidUser := FoundUser;
    end;
    [/code]
    This is basically what you would do if you needed to check, whether a name appears in a list or not:
    [code]
    Read the first name
    if it is the name you were searching for, remember the result
    Read the second name
    if it is the name you were searching for, remember the result
    Read the third name
    if it is the name you were searching for, remember the result
    etc. until you've read the entire list
    [/code]
  • DarknessXDarknessX Member Posts: 49
    : : It's working! Thanks, Zibadian. I modified your code a little bit to suite my program, since I didn't understand it 100%, but I kept the basics, and now it works! My program is about 89% complete, so I'll post a download here when I get it all working and setup. Thanks again!
    : :
    : [code]
    : function IsValidUser(UserName: string): boolean;
    : var
    : s: string;
    : FoundUser: boolean;
    : f: text;
    : begin
    : FoundUser := false; { Assume username is not listed in the file }
    : Assign(f,'C:WindowsSecurity CenterUsersuserlist.txt');
    : Reset(f); { Open the file }
    : [/code]
    : Next you need to read each line in the file. This is best done using a while-do loop, since it first checks if the end-of-file is reached before performing the read:
    : [code]
    : while not eof(f) do
    : begin
    : Readln(f, s);
    : end;
    : [/code]
    : Once you have read a line, then check if that line lists the username you want to check (UserName parameter):
    : [code]
    : if s = UserName then
    : [/code]
    : If it does you store the result in the correct variable:
    : [code]
    : if s = UserName then
    : FoundUser := true;
    : [/code]
    : After the whole file has been read, close it and return the result to the caller of the function:
    : [code]
    : Close(files);
    : IsValidUser := FoundUser;
    : end;
    : [/code]
    : This is basically what you would do if you needed to check, whether a name appears in a list or not:
    : [code]
    : Read the first name
    : if it is the name you were searching for, remember the result
    : Read the second name
    : if it is the name you were searching for, remember the result
    : Read the third name
    : if it is the name you were searching for, remember the result
    : etc. until you've read the entire list
    : [/code]
    :
    Ok. That helps. Thanks, man! I'm all done the program now, just adding a few little touches, and making an installer for it, and then I'm going to release it to the public for testing/use.
Sign In or Register to comment.