I'm Stuck...[please help!?]

FantasiaDown
09-01-2003, 01:45 PM
[Greetings To All]

Okay, so after working on a project application for just less then the past week, 90% of it is completely finished.

The only problem i have is regarding a user password.

I am working on a project application that involves the use of a user password that allows the user to access a personal phone book database of contacts after the user has typed in the right password at the prompt screen following a splash screen i have designed and fired up.

I am in need to know how VB will know whether or not the password is correct,when the user clicks on the "OK' command button.I've also
included a 'Cancel' button, should the user cancel his attempt at going into the database.this cancel button works fine.If the user password is correct, VB will load the 3rd form i've designed and have already coded - being a 'main' screen where the user can access past contact entries for editing,add a new entry for a contact,etc.

I believe i have a very simple idea of what i need the code to do, it is only the proper code 'lingo' itself that i cant figure out.

here what i have so far for the cmdOk button on the user password prompt form....i'm not even sure if what i have for it is even correct at all.

Private Sub cmOK_Click()
Open "a:/comm.dat" For Input As #1
If txtpass = "communicate" Then
Load frmMain
Unload frmCorrect


...am i at all even close to anything that *should* be happening??

"communicate" is the correct password that the user will have to type in - in order to access the personal phone book.

[hmmm] if anyone could possibly help in any form, i would be most grateful. I am completely lost as to what needs to be done!

thank you very much in advance

kunfuzed1
09-01-2003, 02:13 PM
I don't know if you have looked at the login form that comes with vb
here is the code from that if it helps give you an idea of what you want to do... I have always just used this when writing a password protected app.


Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

FantasiaDown
09-01-2003, 02:58 PM
Thanks for your reply!
It sounds interesting and i'd like to give it a try but i fear that i'm confused about some things...

> what do i do about VB knowing what is the correct password and how do i go about making that password readable for VB?

> could you please do me a favour and go through the code you've taken the time to post for ? there are some things about it that i dont exactly understand :

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

thanks again for the help.i appreciate it.








I don't know if you have looked at the login form that comes with vb
here is the code from that if it helps give you an idea of what you want to do... I have always just used this when writing a password protected app.


Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

kunfuzed1
09-01-2003, 03:20 PM
[QUOTEPOST='FantasiaDown']Thanks for your reply!
It sounds interesting and i'd like to give it a try but i fear that i'm confused about some things...

> what do i do about VB knowing what is the correct password and how do i go about making that password readable for VB?

> could you please do me a favour and go through the code you've taken the time to post for ? there are some things about it that i dont exactly understand :

you said you are confused about "thingS" but the only question i see right now is how vb knows the correct password.
to answer that..
Maybe its confusing because they use the word "password" as the password. u can make that say anything, whatever you are looking for the user to enter.



Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then


all that is doing is checking the string in the textbox to make sure it matches whatever you setup as the password.
Hopefully I'm understanding the question right. If not, we can try again.

FantasiaDown
09-01-2003, 09:58 PM
[hi again]

that bit of code you mentioned about the password and such is right,you're understanding what i'm trying to get at - but dont i need VB to open a sequential data file (being the file that contains the correct password) and read it so it knows whether or not the user is putting in the right password? how do i do this?

could you please break down the code that you posted in your first reply? i dont think i'm understanding how its supposed to work out in my scenerio....i apologise for the trouble.but i do thank you for your help!




[QUOTEPOST='FantasiaDown']Thanks for your reply!
It sounds interesting and i'd like to give it a try but i fear that i'm confused about some things...

> what do i do about VB knowing what is the correct password and how do i go about making that password readable for VB?

> could you please do me a favour and go through the code you've taken the time to post for ? there are some things about it that i dont exactly understand :

you said you are confused about "thingS" but the only question i see right now is how vb knows the correct password.
to answer that..
Maybe its confusing because they use the word "password" as the password. u can make that say anything, whatever you are looking for the user to enter.



Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then


all that is doing is checking the string in the textbox to make sure it matches whatever you setup as the password.
Hopefully I'm understanding the question right. If not, we can try again.

kunfuzed1
09-01-2003, 10:41 PM
[hi again]

that bit of code you mentioned about the password and such is right,you're understanding what i'm trying to get at - but dont i need VB to open a sequential data file (being the file that contains the correct password) and read it so it knows whether or not the user is putting in the right password? how do i do this?

could you please break down the code that you posted in your first reply? i dont think i'm understanding how its supposed to work out in my scenerio....i apologise for the trouble.but i do thank you for your help!




[QUOTEPOST='FantasiaDown']Thanks for your reply!
It sounds interesting and i'd like to give it a try but i fear that i'm confused about some things...

> what do i do about VB knowing what is the correct password and how do i go about making that password readable for VB?

> could you please do me a favour and go through the code you've taken the time to post for ? there are some things about it that i dont exactly understand :

you said you are confused about "thingS" but the only question i see right now is how vb knows the correct password.
to answer that..
Maybe its confusing because they use the word "password" as the password. u can make that say anything, whatever you are looking for the user to enter.



Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then


all that is doing is checking the string in the textbox to make sure it matches whatever you setup as the password.
Hopefully I'm understanding the question right. If not, we can try again.

No, you don't need an outside file.. you tell the command button to compare strings..

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then

you are telling it, txtpassword must = "password" in order to proceed to the next step.

In visual basic, go to Project, then Add form, and add the Login Dialog form.. it will give you the form and all the code im talking about.
Then modify it to do what you want it to do. Set the login dialog form which will be called frmlogin by default to the startup form in your project. all you have to do is add one line of code to make it work with your application...

For example... (look for the text in bold)


Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Form1.show ' whatever form you want to come up after the login has been successful
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

FantasiaDown
09-01-2003, 11:00 PM
Okay...with that all said, I am going to try every out and just mess with it again.I know i am capable of coming up with what i'm looking to achieve eventually.somehow.I'll reply with my results as they happen...i dont think this will be at all too difficult.

thanks again so much for your help and such.
its grately appreciated.




[hi again]

that bit of code you mentioned about the password and such is right,you're understanding what i'm trying to get at - but dont i need VB to open a sequential data file (being the file that contains the correct password) and read it so it knows whether or not the user is putting in the right password? how do i do this?

could you please break down the code that you posted in your first reply? i dont think i'm understanding how its supposed to work out in my scenerio....i apologise for the trouble.but i do thank you for your help!




[QUOTEPOST='FantasiaDown']Thanks for your reply!
It sounds interesting and i'd like to give it a try but i fear that i'm confused about some things...

> what do i do about VB knowing what is the correct password and how do i go about making that password readable for VB?

> could you please do me a favour and go through the code you've taken the time to post for ? there are some things about it that i dont exactly understand :

you said you are confused about "thingS" but the only question i see right now is how vb knows the correct password.
to answer that..
Maybe its confusing because they use the word "password" as the password. u can make that say anything, whatever you are looking for the user to enter.



Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then


all that is doing is checking the string in the textbox to make sure it matches whatever you setup as the password.
Hopefully I'm understanding the question right. If not, we can try again.

No, you don't need an outside file.. you tell the command button to compare strings..

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then

you are telling it, txtpassword must = "password" in order to proceed to the next step.

In visual basic, go to Project, then Add form, and add the Login Dialog form.. it will give you the form and all the code im talking about.
Then modify it to do what you want it to do. Set the login dialog form which will be called frmlogin by default to the startup form in your project. all you have to do is add one line of code to make it work with your application...

For example... (look for the text in bold)


Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Form1.show ' whatever form you want to come up after the login has been successful
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub

kunfuzed1
09-01-2003, 11:08 PM
[QUOTEPOST='FantasiaDown']Okay...with that all said, I am going to try every out and just mess with it again.

yeah, it really is a pretty simple thing, I can say that because even I can do it heh. Just play with it and keep asking questions as they come up. I'm confident you will get it tho.. maybe one more idea is to prompt message boxes or something simple to come up instead of showing forms right away if you arent sure how it's all working.
This forum is great for answering questions big and small. so no matter what, you'll get it if you keep at it.

gfleming
09-02-2003, 12:41 AM
Hi FantasiaDown,

The best way to handle passwords is through a registry. You can assign a password to a name at any time, then recall it at will. It is also easy to allow the user to change their own password. The best part is that you do not need to write the password into your code, something you should always avoid.

The code would look something like.



Private Sub Command1_Click()

'this code is used when the user is first inputting their password

'assign the variable
dim strPassword as string 'used to hold the password

'store password in variable
strPassword = txtPassword.text

'save password into registry for the user whose name
'is in txtName
SaveSetting "MyApp", "Passwords", txtName.text, strPassword

'use this code when you want to check a password

'assign stored password to variable
strPassword = GetSetting(appname:="MyApp", section:="Passwords", Key;= txtName.text, Default:=vbNull)

'compare passwords
if strPassword = txtPassword.text then
Password is correct
else
Password is incorrect
end if

'when comparing strings you may prefer
if UCase(Trim(strPassword)) = UCase(Trim(txtPassword.text)) then
Password is correct
else
Password is incorrect
end if

'use this code if you want to delete a user
DeleteSetting "MyApp", "Passwords", txtName.text

'when you delete a user, if their password is asked for
'it will return the default value vbNull, but you can change
'this by changing the default value at the end of
'GetSetting(appname:="MyApp", section:="Passwords", Key;= txtName.text, Default:=vbNull)

'changing a password is as easy as assigning it

'store password in variable
strPassword = txtPassword.text

'save password into registry for the user whose name
'is in txtName
SaveSetting "MyApp", "Passwords", txtName.text, strPassword

'when ever you assign a password, you may want to have the user input it twice,
'then check it before storing it. Can be annoying to fix if wrong passwrd is stored

'you can also assign security levels this way
SaveSetting "MyApp", "Security", txtName.text, "Administrator"

'a good way to decide who gets to do what

'finally, don't forget to check if a user already exists, just see if the ir is already a password in that name.
'all of these values are remain between program loads.



Hope this helps.

[Greetings To All]

Okay, so after working on a project application for just less then the past week, 90% of it is completely finished.

The only problem i have is regarding a user password.

I am working on a project application that involves the use of a user password that allows the user to access a personal phone book database of contacts after the user has typed in the right password at the prompt screen following a splash screen i have designed and fired up.

I am in need to know how VB will know whether or not the password is correct,when the user clicks on the "OK' command button.I've also
included a 'Cancel' button, should the user cancel his attempt at going into the database.this cancel button works fine.If the user password is correct, VB will load the 3rd form i've designed and have already coded - being a 'main' screen where the user can access past contact entries for editing,add a new entry for a contact,etc.

I believe i have a very simple idea of what i need the code to do, it is only the proper code 'lingo' itself that i cant figure out.

here what i have so far for the cmdOk button on the user password prompt form....i'm not even sure if what i have for it is even correct at all.

Private Sub cmOK_Click()
Open "a:/comm.dat" For Input As #1
If txtpass = "communicate" Then
Load frmMain
Unload frmCorrect


...am i at all even close to anything that *should* be happening??

"communicate" is the correct password that the user will have to type in - in order to access the personal phone book.

[hmmm] if anyone could possibly help in any form, i would be most grateful. I am completely lost as to what needs to be done!

thank you very much in advance

FantasiaDown
09-02-2003, 10:26 AM
the only thing i am [still] having problems with, is implementing the password.i am not sure how to set up the password so that any user can use it, as long as the password is correct....

How do i code what i wish the password to be in the code editing window so after the correct password has been entered, the Mainfrm (being the 3rd form will load) ? the green dialog included in both code is throwing me off a bit and i dont understand it. i am so frustrated! i feel as if i've tried everything.

I apologise if i'm a bit too much trouble.I want to learn everything i possibly can but it is nice to be set in the right direction.

thanks again for all the help and advice given so far.
its appreciated !

FantasiaDown
09-02-2003, 10:47 AM
I've figured it out! [w00 h00] so proud of myself i am.
thanks for the help on that particular problem.it was quite simple afterall!

now, suppose i did want VB to open a sequential file to read the correct password and verify that whatever the user was putting in was correct?
how would i go about doing that ?

Thank you!






the only thing i am [still] having problems with, is implementing the password.i am not sure how to set up the password so that any user can use it, as long as the password is correct....

How do i code what i wish the password to be in the code editing window so after the correct password has been entered, the Mainfrm (being the 3rd form will load) ? the green dialog included in both code is throwing me off a bit and i dont understand it. i am so frustrated! i feel as if i've tried everything.

I apologise if i'm a bit too much trouble.I want to learn everything i possibly can but it is nice to be set in the right direction.

thanks again for all the help and advice given so far.
its appreciated !

kunfuzed1
09-02-2003, 11:29 AM
[QUOTEPOST='FantasiaDown']I've figured it out! [w00 h00] so proud of myself i am.
thanks for the help on that particular problem.it was quite simple afterall!

now, suppose i did want VB to open a sequential file to read the correct password and verify that whatever the user was putting in was correct?
how would i go about doing that ?

Thank you!

I would go with what gfleming said.. i dont know why its not a good idea to work the password into the code, but then again there are a lot of things i don't know. So i'm more apt to believe another before myself when it comes to this stuff. I just offered my two cents on the matter, i think his two cents is worth a bit more than mine tho. So,work with the code he submitted and see what you can do with it. I think that will solve the problem of having the password read outside of the program if that's what you are going for.

gfleming
09-02-2003, 12:12 PM
Hi there,

I have lost track of who is wanting to know what, so this is to both kunfuzed1 and FantasiaDown.


The reason that it is not a good idea to set the password in code is that it is then unchangable. I am not sure exactly sure what program you are writing, or how it is to be used. So lets assume that it is a program that is used in a work setting by all employees in a particular work group. Lets also assume that there is also a pupose (other than showing off our programming skills) for having a password. What do you do if their is a security risk when employees change jobs? What if someone that you do not want to have access to the program somehow learns the password?What if, in the future, you want individual users to have their own password as a way of tracking who does what? This program may only be used by family at the moment, what if that changes.

It is because of the "what if's" that I would not choose to code a password.

I am not sure how to do the sequential file thing, but if you are hell bent on coding the password, here is how I would do it.

Note: the green comments are there to help people read code (funny really, considering they have confused you). Any comment made after an apostrophy is not read by the programe, just people


'to save the password
SaveSetting "MyApp", "Passwords", "mainPassword", "PlacecePasswordHere"

'use this code when you want to check a password

'assign stored password to variable
strPassword = GetSetting(appname:="MyApp", section:="Passwords", Key;= txtName.text, Default:=vbNull)

'compare passwords
If strPassword = txtPassword.text Then
PasswordIsCorrect
LetUserIn
Else
PasswordIsIncorrect
Tell user to try again
End If



if you want the password to be ABRACADABRA, you would replace

SaveSetting "MyApp", "Passwords", "mainPassword", "PlacePasswordHere"

with

SaveSetting "MyApp", "Passwords", "mainPassword", "ABRACADABRA"

in the above code.

Hope this is clearer.

FantasiaDown
09-03-2003, 07:32 AM
I thank you for your help, gfleming.
I understand completely what you're saying but its much more dry-cut then all of these technical possibilities of 'what if'. I am in a university internship working for a small software company and they've given me the opportunity to take on this challenge of setting up a 'mock' application of a personal phone book.I say 'mock' because they are grading me on how i can make the application to work on a very basic level, without the worries of the possibily of wanting to change the password at a later time, or the worry of a non-favoured person misusing the application.

maybe i should have stated this long ago, and for that i apologise.

and as far as the green dialog is concerned, i was just confused as to take the green dialog as if you were speaking to me directly (as an instruction for me to do), or if i was to include that into code exactly.
thats all.I am quite aware of what the green dialog is used for, but in this instance i just wasnt sure...a bit of a misunderstanding is all that it is.

so....this sequential file stuff!
its still being rather a pain for me - though your code (gfleming) has put me in the right direction a bit.so i thank you for that.
I will write again as there is progress.

thanks again for your patience and help.

ps - out of curiosity, what is meant by "MyApp" ?

-- > SaveSetting "MyApp", "Passwords", "mainPassword", "PlacePasswordHere"

thank you !


Hi there,

I have lost track of who is wanting to know what, so this is to both kunfuzed1 and FantasiaDown.


The reason that it is not a good idea to set the password in code is that it is then unchangable. I am not sure exactly sure what program you are writing, or how it is to be used. So lets assume that it is a program that is used in a work setting by all employees in a particular work group. Lets also assume that there is also a pupose (other than showing off our programming skills) for having a password. What do you do if their is a security risk when employees change jobs? What if someone that you do not want to have access to the program somehow learns the password?What if, in the future, you want individual users to have their own password as a way of tracking who does what? This program may only be used by family at the moment, what if that changes.

It is because of the "what if's" that I would not choose to code a password.

I am not sure how to do the sequential file thing, but if you are hell bent on coding the password, here is how I would do it.

Note: the green comments are there to help people read code (funny really, considering they have confused you). Any comment made after an apostrophy is not read by the programe, just people


'to save the password
SaveSetting "MyApp", "Passwords", "mainPassword", "PlacecePasswordHere"

'use this code when you want to check a password

'assign stored password to variable
strPassword = GetSetting(appname:="MyApp", section:="Passwords", Key;= txtName.text, Default:=vbNull)

'compare passwords
If strPassword = txtPassword.text Then
PasswordIsCorrect
LetUserIn
Else
PasswordIsIncorrect
Tell user to try again
End If



if you want the password to be ABRACADABRA, you would replace

SaveSetting "MyApp", "Passwords", "mainPassword", "PlacePasswordHere"

with

SaveSetting "MyApp", "Passwords", "mainPassword", "ABRACADABRA"

in the above code.

Hope this is clearer.

gfleming
09-03-2003, 10:19 AM
MyApps, I assume is an abreviation for "my application".

This means that there is 1 registry for all applications, and so you need to state what application (program name) you refer to.


I thank you for your help, gfleming.
I understand completely what you're saying but its much more dry-cut then all of these technical possibilities of 'what if'. I am in a university internship working for a small software company and they've given me the opportunity to take on this challenge of setting up a 'mock' application of a personal phone book.I say 'mock' because they are grading me on how i can make the application to work on a very basic level, without the worries of the possibily of wanting to change the password at a later time, or the worry of a non-favoured person misusing the application.

maybe i should have stated this long ago, and for that i apologise.

and as far as the green dialog is concerned, i was just confused as to take the green dialog as if you were speaking to me directly (as an instruction for me to do), or if i was to include that into code exactly.
thats all.I am quite aware of what the green dialog is used for, but in this instance i just wasnt sure...a bit of a misunderstanding is all that it is.

so....this sequential file stuff!
its still being rather a pain for me - though your code (gfleming) has put me in the right direction a bit.so i thank you for that.
I will write again as there is progress.

thanks again for your patience and help.

ps - out of curiosity, what is meant by "MyApp" ?

-- > SaveSetting "MyApp", "Passwords", "mainPassword", "PlacePasswordHere"

thank you !


Hi there,

I have lost track of who is wanting to know what, so this is to both kunfuzed1 and FantasiaDown.


The reason that it is not a good idea to set the password in code is that it is then unchangable. I am not sure exactly sure what program you are writing, or how it is to be used. So lets assume that it is a program that is used in a work setting by all employees in a particular work group. Lets also assume that there is also a pupose (other than showing off our programming skills) for having a password. What do you do if their is a security risk when employees change jobs? What if someone that you do not want to have access to the program somehow learns the password?What if, in the future, you want individual users to have their own password as a way of tracking who does what? This program may only be used by family at the moment, what if that changes.

It is because of the "what if's" that I would not choose to code a password.

I am not sure how to do the sequential file thing, but if you are hell bent on coding the password, here is how I would do it.

Note: the green comments are there to help people read code (funny really, considering they have confused you). Any comment made after an apostrophy is not read by the programe, just people


'to save the password
SaveSetting "MyApp", "Passwords", "mainPassword", "PlacecePasswordHere"

'use this code when you want to check a password

'assign stored password to variable
strPassword = GetSetting(appname:="MyApp", section:="Passwords", Key;= txtName.text, Default:=vbNull)

'compare passwords
If strPassword = txtPassword.text Then
PasswordIsCorrect
LetUserIn
Else
PasswordIsIncorrect
Tell user to try again
End If



if you want the password to be ABRACADABRA, you would replace

SaveSetting "MyApp", "Passwords", "mainPassword", "PlacePasswordHere"

with

SaveSetting "MyApp", "Passwords", "mainPassword", "ABRACADABRA"

in the above code.

Hope this is clearer.

eugenen
10-18-2003, 04:12 AM
Just A Thought I have a app that uses a login username and password... you said it would be a database with tel numbers etc. well why dont jou just add a extra table to the database with usernames,passwords etc... and just read the password from the db and compare it to the one entered? This is how i did my app and it is fool proof if you have questions please let me know then i can post the code.

hope I made a contrabution

cheers

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum