stopping access

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
=D

stopping access

Post by =D »

<p>
Ok well how would i go about stoping access to a text file that is use in my QBASIC program? can be this be done?
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

like this, lets say you have opened file #1 and are ready to close it. Hence the close.

CLOSE #1

like that, or

CLOSE#n
Where n is the file number[/i]
=D

re

Post by =D »

Let me say that again , what i ment was is ther a way to stop people getting into this text file, like can on opening of the text file it opens a QB file witch closes it, i could make this text file hyper text so is ther any html code that opens a file on load?


barok
Coder
Posts: 38
Joined: Sat Jul 24, 2004 4:32 pm
Location: Frozen bushlands of Saskatchewan

Post by barok »

You're being very unclear. Try again. Use proper punctuation, use something else instead of red, which clashes with white, and try to make your message understandable.

What you are asking for is impossible. You want a program that prevents people from accessing a file. The best thing to do is encrypt the file. Encrypting will make the file unreadable to anyone without the decrypter. Or you could save as binary, you could compress the file into your own format, or at the least you could rename the extension. for example, instead of file.txt you could have file.dat.
I have no sig.
Guest

Post by Guest »

i have come up with this code below but when u test it, it says file alredy open but i closed it can someone help

Code: Select all

CLS
OPEN "mac.dat" FOR INPUT AS #1
  INPUT #1, S$
  PRINT S$
IF S$ = "****  BLOCKED  ****" THEN GOTO 12 ELSE GOTO 13
CLOSE #1





13 : PRINT "** THIS PROGRAM IS PASSWORD PROTECTED **"

PRINT "*  ENTER PASSWORD  *"
INPUT pass$
IF pass$ = "king" THEN GOTO 1 ELSE GOTO 3




3 PRINT "***  FAIL  ***"
PRINT "**  ENTER PASSWROD  **"

INPUT pass$
IF pass$ = "king" THEN GOTO 1 ELSE GOTO 4
4 PRINT "**  FAIL **"
PRINT "***  ENTER PASSWORD  ***"
INPUT pass$
IF pass$ = "king" THEN GOTO 1 ELSE GOTO 5
5
12 :
OPEN "file.txt" FOR OUTPUT AS #1
  PRINT #1, "****  BLOCKED  ****"
  CLOSE #1

PRINT "********* BLOCKED **********"

END






1 PRINT "** Access Granted **"

END


  

Guest

Post by Guest »

ooops were it says file.txt thats ment to be mac.dat but this still dose not solve my probmlem
barok
Coder
Posts: 38
Joined: Sat Jul 24, 2004 4:32 pm
Location: Frozen bushlands of Saskatchewan

Post by barok »

use freefile instead of just choosing #1. using this you can avoid this.

number = freefile

open "file.txt" for input as #number


ugh... spaghetti code. that's something you really want to avoid.

btw, did you hear me? what your asking for is impossible with qb!
I have no sig.
Guest

Post by Guest »

hmm ok i will give that ago and yes i no what u said so i have gone off that idea this is something new .... 1 more thing if u could help me would be to tell me how to turn my files into banary?? ty
barok
Coder
Posts: 38
Joined: Sat Jul 24, 2004 4:32 pm
Location: Frozen bushlands of Saskatchewan

Post by barok »

first, open the file. then copy all of it's contents into variables. then open the file for binary:

open "file.txt" for binary as #filenum

and save all the contents.
I have no sig.
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Well, it can be done in QB.

You have a file, that is encrypted.

If the file is missing, lock down the program.
If the unencrypted thing says "locked" lock down the program.

Most secure you can go.


Or you could just store the file in let's say:
C:\Windows\System\MSWDLL.DRV

Or some other equally cryptic name.

Just make sure to store the path as CHR$() statements and not plaintext, as plaintext can be easily found.
I have left this dump.
Digital Shadow
Coder
Posts: 23
Joined: Sun Oct 03, 2004 10:26 pm
Location: Prince George, BC, Canada

Post by Digital Shadow »

carefull with that open as output, that erases the file and remakes it, look into APPEND, unless thats what you want...
People laugh at me because I'm different, I laugh because there all the same... Soooo, if were all laughing, I fail to see the problem
Digital Shadow
Coder
Posts: 23
Joined: Sun Oct 03, 2004 10:26 pm
Location: Prince George, BC, Canada

Post by Digital Shadow »

and optimize that spag...

Code: Select all

CLS

OPEN "mac.dat" FOR INPUT AS #1
  INPUT #1, S$ 
  PRINT S$ 
  IF S$ = "****  BLOCKED  ****" THEN GOTO Block ELSE GOTO Pass 
CLOSE #1

Pass: 
  PRINT "** THIS PROGRAM IS PASSWORD PROTECTED **" 
  For a=1 to 3
    PRINT "*  ENTER PASSWORD  *" 
    INPUT pass$ 
    IF pass$ = "king" THEN GOTO Access
    PRINT "***  FAIL  ***"
  NEXT a 

Block: 
  OPEN "file.txt" FOR OUTPUT AS #1 
    PRINT #1, "****  BLOCKED  ****" 
  CLOSE #1 
  PRINT "********* BLOCKED **********" 
  END 

Access:
  PRINT "** Access Granted **" 
  END 
ahh.... much better[/code]
People laugh at me because I'm different, I laugh because there all the same... Soooo, if were all laughing, I fail to see the problem
Post Reply