Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Canada
 Pete Sass
 To: munir hossain
  Where is munir hossain?
 dhaka
 Bangladesh
 munir hossain
 Tags
Subject: RE: password protection
Thread ID: 16183 Message ID: 16202 # Views: 2 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Friday, October 11, 2002 11:08:38 AM         
   


> > >
> > > hello there
> > > i created few form and want to enter password when user run those form.how can i do this? please
> > > help me.i place a text box to hold a password but don't know how i do it.
> >
> > maybe this could lead you in the path
> >
> >
> > LOCAL oPasswordedForm as Form, txtPassword as TextBox 
> > SET talk OFF
> > SET NOTIFY OFF
> > 
> > oPasswordedForm = CREATEOBJECT("form")
> > 
> > oPasswordedForm.AutoCenter = .T.
> > oPasswordedForm.Caption="Please enter your password.."
> > oPasswordedForm.Height=125
> > oPasswordedForm.Width =255
> > oPasswordedForm.AddObject("txtPassword","MyPasswordedTextBox")
> > oPasswordedForm.txtPassword.Visible = .T.
> > oPasswordedForm.AddObject("cmdExit","MyExitButton")
> > oPasswordedForm.cmdExit.Visible = .T.
> > oPasswordedForm.Show
> > READ event
> > 
> > 
> > DEFINE CLASS MyPasswordedTextBox as TextBox 
> > 	Visible 		= .T.
> > 	PasswordChar 	= [*]
> > 	selectonentry	= .t.
> > 	Left 			= 75
> > 	Top  			= 25
> > 	TabIndex		= 1
> > 	
> > 
> > 	PROCEDURE VALID 
> > 		lValueReturn = .T.
> > 		IF !EMPTY(This.Value) then
> > 			IF ALLTRIM(This.Value) = "mypassword" then
> > 				MESSAGEBOX("password correct!")
> > 			ELSE
> > 				MESSAGEBOX("Password Icorrect!")
> > 				lValueReturn = .F.
> > 			ENDIF
> > 		ENDIF
> > 		RETURN lValueReturn 
> > ENDDEFINE
> > 
> > DEFINE CLASS MyExitButton as COMMANDBUTTON
> > 	Visible 		= .T.
> > 	Left 			= 85
> > 	Top  			= 85
> > 	Width 			= 80
> > 	Height			= 30
> > 	caption			= "Exit"
> > 	
> > 
> > 	PROCEDURE CLICK
> > 		ThisForm.Release
> > 		CLEAR EVENTS 
> > ENDDEFINE
> > 

> >
> > regards
> > Karben Selim Mejia
> >
> > I always have the last word in my home, "Yes sweet heart, what ever you say"
> >
> > Honduras, Central America
> > The very center of the world
>
>
> But if i want to give user a choice to change password from a form for my software
> how i will do it.




Hi for Pete,

First off lets talk basics.......
You need a table with a minimum of 2 fields in it. One field for the UserID and
the other field for the Users Password. Call the table Security,
or what-ever you want that makes sense to you.
Make both of these fields character fields with say a length of 12.
Create a CDX index tag on the UserID.

Now create a simple form and add two textboxes, one for the UserID field and one
for the Password. In this forms dataenvironment have the Security table added
with the order set to UserID and buffering=5.
Name one textbox txtUserId, the other txtPassword.
On this form right click on the txtUserId textbox which will bring
up the properties window. Then go to the Layout Tab. Look for a
property called PasswordChar and enter a * in here. Now when the
user enters his/her password all anyone will see is ********
for the password entry.

On the lostfocus event of the txtUserId get the userid out of the textbox
and seek on the value in the Security table:
cPassword=Rtrim(Thisform.txtUserId.Value)
Select Security
SEEK cPassword
If .Not. Found()
Wait "Invalid Uder ID, try again !" Window
Thisform.txtUserId.Value=""
NODEFAULT
Return
Endif

Now you record pointer in the Security table is sitting on the
user's id that is attempting to log in.

Now on the lostfocus even of the txtPassword input box
simple check to see if the passwords match:
If RTRIM(Thisform.txtPassword.Value)== Security.Password

* --- What ever you are doing with a successful login

ELSE
Wait "User Password is invalid... Try to log in again !" Window
Thisform.txtPassword.Value=""
NODEFAULT
Return
ENDIF



Ok... now for the second part of your question... how to allow the
user to change his/her own password.
Now all you have to do is create a form with 4 textboxes on it.
Set it's dataevironment up the same as described above in the
simple password screen.
On the form have these entries for the user
User ID:
Old Password:
New Password:
Confirm New Passord:
and an Accept and Cancel button

The lostfocus event from the User ID input does the same as in the
simple password form, seeks to the user id match.
The lostfocus event from the Old Password entry validated that
when the user entered and what is in the Security table for that
user matches.
The user then enters the new password, and enters it again
to ensure accuracy. You will validate that the New Password
and Confirm New Password entries match. If not, call up
a Messagebox and advise the user to enter the New Password,
and Confirm New Password's again.
If they match, set the focus to the Accept button. When the user
click it:
Select Security
REPLACE Security.Password WITH RTRIM(Thisform.txtNewPassword.Value)
=TABLEUPDATE()
Wait "Your User ID has been changed sucuessfully !"
Thisform.Release

The examples I have given above are very basic, and hope it gives
you the idea of a basic User and Password login, and how the
user can with your code change their own passwords.

Pete from the Great White North ! (Only in Canada, ay...) Over and Out ...


ENTIRE THREAD

password protection Posted by munir hossain @ 10/10/2002 10:44:32 PM
RE: password protection Posted by Karben Selim Mejia @ 10/10/2002 11:18:52 PM
RE: password protection Posted by munir hossain @ 10/11/2002 8:50:10 AM
RE: password protection Posted by Pete Sass @ 10/11/2002 11:08:38 AM