[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

saving and recurring text files.

I have a Register screen it has a username(Text1), password(Text2), e-mail address (text3. I have got a text file with the username and e-mail address in it(marc.txt). when someone hits submit i want the program to look at the text file (marc.txt) and see if the username, password are real. If so End, If not go to form2. Also then save the password to a text file but call it marc2.hhh. the next person who uses this program will have to enter the password again and again i want it to save to a text file called marc2.hhh but not overwrite the previous saved password.


these are all my points sorry.
0
dog3
Asked:
dog3
1 Solution
 
greischCommented:
Do you have marc.txt (and marc2.hhh) for user marc,
paul.txt for user paul, ... ?
Do you have marc.txt for all users ?
Do you have one or more users ?
The password is in marc.txt (with name & e-mail) ?
0
 
DalinCommented:
dog3
try this:
' I assume you saved the 3 items in the file in the order of
UserName  Password  Email

' Check passwaord
Dim lLine as String
Dim lInt as Integer
Dim lUserName as String
Dim lPswd as String
Dim fnum as Integer
Dim lValid as Boolean

lValid = False
fNum = FreeFile
Open "marc.txt" for input as fnum

Do while not EOF(fnum)
    Line Input #fnum, lLine
    lInt = Instr(lLine, " ")
    lUserName = Left(LLine, lInt-1)
    lLine = Right(lLine, Len(lLine)-Int)
    lInt = Instr(lLine, " ")
    lPswd = Left(lLine, lInt)
    If  lUserName = text1 and lPsWd = Text2 Then
            lValid = True
            Exit Do
         End if
    Loop
  If lValid = True then
      'Do what you do, end?
      Else
        form2.Show
    End If

Let me knoe if you have any questions
Regards
Dalin

   

0
 
dog3Author Commented:
Marc.txt has all usernames and domains.
Marc.txt is where i want the password to be stored.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dog3Author Commented:
no you may of not read my comment after it.
0
 
DalinCommented:
dog3,
I would suggest you put all username/paswd/email in one file (marc.txt) in a format:
UserName Password Email
dog3 yourPass dog3@anyMail.com
Dalin myPswd Dalin_N@MailExcite.com
Whoelse hispsword where@Ever.Com
.
0
 
dog3Author Commented:
no you may of not read my comment after it.
0
 
dog3Author Commented:
no you see i'm a system admin and i need 1 text file which has username and e-mail
then another which will collect the passwords.
0
 
DalinCommented:
dog3,
Do you mean you don't have your password in marc.txt yet?

0
 
dog3Author Commented:
no you see i'm a system admin and i need 1 text file which has username and e-mail
then another which will collect the passwords.
0
 
dog3Author Commented:
no i do not have the password and want it in marc.hhh
but only in there if the username and e-mail are right.
0
 
dog3Author Commented:
no i do not have the password and want it in marc.hhh
but only in there if the username and e-mail are right.
0
 
dog3Author Commented:
the password and username are stored in marc.txt
0
 
DalinCommented:
dog3,
Let me see if I understand you now..
You have a fiel called marc.txt containing  username and email
you have a file called marc.hhh tcontaining the password for the users in marc.txt.

When someone login, the/she supply you with a username/password/email via text1/text2/text3
If this username is in marc.txt and he give the right psword, OK
If the userName does not match the password then show form 2.

Please comment
Regards

0
 
clifABBCommented:
This is so confusing!

I would suggest you drop the idea of a txt file and use either the registry or an ini file.  Both are much easier to read/write.
0
 
dog3Author Commented:
Ok here we go.
if username and e-mail address are in marc.txt
marc.hhh is empty.

when a person types in the right username and e-mail
store the password in marc.hhh

--------------------------Example of Marc.txt--------------
1
2
3
1@2.com for all users there are the same e-mail address.
-----------------------------------End marc.txt ---------------



0
 
dog3Author Commented:
ok you can use ini's
but make marc.txt, marc.ini
and marc.hhh, marc.ini
0
 
DalinCommented:
dog3,
So you do not want to use the password to validate?
As long as the username and e-mail matches what's in marc.txt, then valid?

But you do not have the userName and it's email in some corresponding way?

I thought your marc.txt file should be:
User1 user1@something.edu
User2 user2@whatever.com
User3 user3@somewhere.org
.
0
 
cymbolicCommented:
Just a suggestion to simplify the issue.  Why not manually construct with an editor a sample of what you expect your two files to look like, on first use, and after the second use.  Then someone can use these to create and test code for you, if you can't do it your self by then.  I would recommend for program simplification that you go with a fixed length typed structure,then use binary file i/o to read/write the type.  Also, if storing passwords, use some type of encryption algorithm to avoid security problems.  

If your ultimate goal is just to track logons, note that in NT a security log data set is created by NT that can be saved automatically and imported into a database to retain searchable history.

 
0
 
dog3Author Commented:
stuff the e-mail part

all usernames are in marc.ini/txt (whatever)
ok if the e-mail box = "cabra" than it is valid
but if not "cabra" or "username" not valid and go to form2
if boath username and e-mail are valid store password in marc2.hhh/.txt/.ini

ok clear?
Marc.txt contains usernames
Marc2.txt contains the valid users passwords
and the e-mail box HAS to equal cabra lower caps.


0
 
DalinCommented:
let me see if I understand...

'Check valid logon
       Dim lUserName as String
       Dim lPswd as String
       Dim fnum as Integer
       Dim lValid as Boolean
       dim fPsNum as Integer

       lValid = False
       If text3 = "cabra" then
           fNum = FreeFile
           Open "marc.txt" for input as fnum

           Do while not EOF(fnum)
           Line Input #fnum, lUserName
           If  lUserName = text1
                   lValid = True
                   Exit Do
                End if
           Loop
           Close #Fnum

         If lValid = True then
             'Store the password
             lPswd = Text2
             fNum = FreeFile
             Open "Marc2.txt" for Append as #fNum
             Print #FNum, lPswd
             Close #FNum
             Else
               form2.Show
           End If

0
 
SekansCommented:
I made a similar logon screen with Username/Password.  I stored the names and passwords in a password locked .mdb.  When the user submitted each I scanned the mdb for the username tested to see if the password matched, if it did...Welcome.  However, I realize this may not be the solution for you.  Just a thought.

Regards,
Sekans
0
 
dog3Author Commented:
i can't get this to work could you e-mail the whole project including the 2 text files to me then i wil give you the points.
0
 
DalinCommented:
dog3,
I tested this code and it works like this:

If the email entry is cabra, it will go down the list of Username in the file marc.txt (the file only have username, with one in each line) to see if the entered user name is in the list. If yes, write the entered password to file marc2.txt.
Anyother cases, show form 2.
This is how I did it:

1. have a file edited, save as marc.txt, with content of:
dalin
Dog3
Who
somebady

2. start a new VB project
3. drop 3 text box, name them txtEmail, txtUserName, txtPassword
4. add another form
5. drop 1 command button, name it cmdLogin

6. In the cmdLogin_Click event, add the code:

Dim lUserName As String
Dim lPswd As String
Dim fnum As Integer
Dim lValid As Boolean
Dim fPsNum As Integer
Dim fPsNum As Integer

lValid = False
If txtEmail.Text = "cabra" Then
    fnum = FreeFile
    Open "C:\Dalin\marc.txt" For Input As fnum

    Do While Not EOF(fnum)
        Line Input #fnum, lUserName
             If lUserName = txtUserName.Text Then
                    lValid = True
                    Exit Do
                End If
        Loop
        Close #fnum
    End If

    If lValid = True Then
        'Store the password
        lPswd = txtPassword.Text
        fnum = FreeFile
        Open "C:\Dalin\Marc2.txt" For Append As #fnum
        Print #fnum, lPswd
        Close #fnum
    Else
        Form2.Show
    End If

End Sub

7.Run the project, enter cabra in txtEmail, dog3 in txtUserName, mypass in txtPassword, then click cmdlogin

Now you should have a file in c: called marc2.txt, with mypass in it.

8. again, enter something other than cabra in e-mail, you should see form2.

If you have problem, email me your project. My e-mail: Dalin_N@mailexcite.com

Regards
Dalin

0
 
dog3Author Commented:
Thanks!!!
0
 
DalinCommented:
dog3,
1. You can read the text file into a ftring variable since you do not need to show it.

Dim lString as String
Dim lLine as String
Dim fNum as Integer

Open "YourTxtFileWithPath.txt" for input as fnum
Do while not EOF(fnum)
     Line Input #fnum, lLine
     lString = lString & lLine
   Loop
Close #Fnum

Now lString has your txt File.

I was not clear on your 2nd question, can you clearify?
Regards
Dalin

>Thanks for doing that code it realy well.
>i was wondering if you knew how to load a text file into a hidden text =
>box?
>
>is there a way which you can type */www.txt  ?
>where the star is it means where ever the program is installed
>eg d:\1\ is where it is installed so www.txt is in d:\1\
>     c:\2\ is where it is installed so www.txt is in c:\2\
>ect please tell me=20
>thx
>
>
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now