Create login table and form in VFP ?
-
Friday, July 10, 2009 4:09 AMI want create login form and login table in my my programe.
But I don't know to make how ????
Who know it, please !!
Tell me the way make it. Thank!!!!
All Replies
-
Friday, July 10, 2009 12:17 PM
There are many ways to do this, but basically it can be reduce to this steps:
1 - Launch login form where users can enter user name and password
2 - verify user name and password against users database
3 - if user name/password combination match launch application otherwise comback to login form.
Here are a couple links that shows you some examples you can use
http://www.west-wind.com/WebConnection/docs/_02u154zlp.htm
http://gentirit.com/load-form-login-di-form-utama-vfp.html
Of course, you also need a way to create users.
Also in the "Tastrade" samples that comes with Fox there is also a simple "Login" scenario.
Good Luck- Marked As Answer by Riquel_Dong Thursday, July 16, 2009 9:19 AM
-
Monday, July 13, 2009 3:47 PM
*********************************************************
*...PROC CRPASS FOR CREATING SIMPLE PASSWORD *
*...PROC CRPASS *
*...COPY THIS CODE AND TRY *
*********************************************************
SET TALK OFF
SET ANSI ON
SET EXACT ON
SET SAFETY OFFPUBLIC MPASS,MUSERID
*...Create a dbf file on c:\drive of every user in this example
*..its name is acceps ..and have three fields userid,expflg(expire flag)
*..of pass word and pass (PASSWORD)
*..initiate userid and passIF !FILE("C:\ACCEPS.DBF")
CREATE TABLE c:\acceps (userid c(10),expflg n(1),pass c(10))
APPEN BLANK
REPLACE userid WITH "user1"
REPLACE pass WITH "user1"
ENDIFUSE C:\ACCEPS EXCLUSIVE
*..IN EVERY RECORD USERID IS SAME EVEN expired one's
MUSERID = USERID
*..............................................................*
frmMy = CREATEOBJECT('Form') && Create a Form
frmMy.Closable = .F. && Disable the Control menu box
frmMy.Caption = "System Password Screen "
frmMy.autoCenter = .t.
frmMy.height=300
frmMy.width =370
frmMy.maxbutton =.f.
frmMy.minbutton =.f.
frmMy.movable =.f.
frmMy.sizebox =.f.frmMy.AddObject('cmd1','Btn1')
frmMy.AddObject('cmd2','Btn2')
frmMy.AddObject('cmd3','Btn3')frmMy.AddObject('text11','txt1')
frmMy.AddObject('text22','txt2')
frmMy.AddObject('text33','txt3')
frmMy.AddObject('label11','label1')
frmMy.AddObject('label22','label2')
frmMy.AddObject('label33','label3')frmMy.cmd1.Visible =.T.
frmMy.cmd2.Visible =.f.
frmMy.cmd3.Visible =.T.frmMy.text11.Visible =.T.
frmMy.text33.value = muserid
frmMy.text33.visible =.t.
frmMy.text33.readonly =.t.frmMy.label11.Visible =.T.
frmMy.label22.Visible =.T.
frmMy.label33.Visible =.T.
frmMy.text11.setfocus()
*................................................................*
frmMy.SHOW && Display the form
READ EVENTS && Start event processing
close data
if mpass=.f.
Quit
endif
RETURN
*.....................................................*
Procedure koka
DEFINE CLASS txt1 AS textbox && Create button
Left = 20
Top = 55
Height = 25
width = 200
passwordchar="*"
PROCEDURE gotfocus()
frmMy.cmd2.Visible =.f.
PROCEDURE lostfocus()
frmMy.cmd3.setfocus()
frmMy.cmd1.click()
ENDDEFINEDEFINE CLASS txt2 AS textbox && Create button
Left = 20
Top = 80
Height = 25
width = 200
passwordchar="*"PROCEDURE lostfocus()
do while .t.
if empty(frmmy.text22.value)
= messagebox( "EMPATY PASSWORD" )
mpass=.t.
exit
endif
if len( allt(frmmy.text22.value))<5
=messagebox ( "PASSWORD IS LESS THAN 5 CHR'S" )
mpass=.t.
exit
endif
close data
Use "c:\acceps" excl
locate for allt(uppe(pass))=allt(uppe(frmmy.text11.value)) .and. expflg=0 ;
.and. allt(uppe(userid))=allt(uppe(muserid))
if found()
replace expflg with 1
endif
Appen blank
replace acceps.userid with allt(muserid)
replace acceps.pass with allt(frmmy.text22.value)
replace acceps.expflg with 0
delete for expflg = 1
pack
close data
mpass=.t.
=messagebox ("PASSWORD CHANGED")
exit
enddo
frmMy.cmd3.click()
PROCEDURE setfocus()
ENDDEFINEDEFINE CLASS txt3 AS textbox && Create button
Left = 20
Top = 32
Height = 21
width = 200
fontsize=9
PROCEDURE click()
ENDDEFINE
DEFINE CLASS Btn1 AS COMMANDBUTTON && Create button
Caption = 'Ok'
Left = 50
Top = 130
Height = 25
PROCEDURE Click
close data
Use "c:\acceps" excl && for single user
locate for allt(uppe(pass))=allt(uppe(frmmy.text11.value)) ;
.and. allt(uppe(userid))=allt(uppe(muserid)) .and. expflg=0
if found()
mpass=.t.
frmMy.cmd2.Visible =.t.
else
=messagebox("INCORRECT PASSWORD")
frmmy.text11.value =space(20)
mpass=.f.
endif
ENDDEFINEDEFINE CLASS Btn2 AS COMMANDBUTTON && Create Command button
Caption = 'Change'
Left = 200
Top = 130
Height = 25PROCEDURE Click
frmMy.text22.Visible =.T.
frmMy.text11.readonly =.T.
frmMy.text22.setfocus()
ENDDEFINE
*..........................................................................*
DEFINE CLASS Btn3 AS CommandButton && Create Command button
Caption = '\<Close' && Caption on the Command button
Cancel = .T. && Default Cancel Command button (Esc)
Left = 125 && Command button column
Top = 170 && Command button row
Height = 25 && Command button height
PROCEDURE Click
frmMy.release()
CLEAR EVENTS && Stop event processing, close Form
ENDDEFINEDEFINE CLASS label1 AS label
Caption = 'Enter Password'
Left = 20
Top = 10
Height = 15
width = 130
forecolor=rgb(120,4,110)
fontsize=12
ENDDEFINEDEFINE CLASS label2 AS label
Caption = 'SAMPLE CODE'
Left = 15
Top = 220
Height = 18
width = 400
forecolor=rgb(0,4,220)
fontsize= 10
ENDDEFINE
DEFINE CLASS label3 AS label
Caption = '..........USING VFP CODE........ '
Left = 33
Top = 260
Height = 18
width = 400
forecolor=rgb(128,0,128)
fontsize= 10
ENDDEFINE
azizsallam- Marked As Answer by Riquel_Dong Thursday, July 16, 2009 9:19 AM
-
Monday, July 13, 2009 8:34 PMAnswererPlease don't offer people suggestions that involve public variables. They're a very bad idea.
Tamar -
Tuesday, July 14, 2009 4:32 AM
Hi Minh,
This piece of code will give you a better idea than the previous links I sent to you, hope this help you out, it should work without changes. - LuisLOCAL oForm,; lcDataPath,; lcTable,; lnRtnVal,; lnMaxAttempts lcDataPath = "c:\delete\" &&Replace with your own path lcUsersTable = 'SystemUsers' &&Replace with the name of your table lcFullName = lcDataPath + lcUsersTable + ".dbf" lnMaxAttempts = 3 &&Set the maxmum number of attempts desired, 0 infinite IF !USED(lcUsersTable) IF !FILE(lcFullName) CREATE TABLE &lcFullName (cUserName C(20), cUserPass C(20), lLocked L) SELECT (lcUsersTable) INDEX ON ALLTRIM(cUserName) TAG cUserName APPEND BLANK REPLACE cUserName WITH "User1" IN (lcUsersTable) REPLACE cUserPass WITH "Pass1" IN (lcUsersTable) APPEND BLANK REPLACE cUserName WITH "User2" IN (lcUsersTable) REPLACE cUserPass WITH "Pass2" IN (lcUsersTable) ELSE USE (lcFullName) IN 0 SHARED ENDIF ENDIF oForm = CREATEOBJECT("Login") oForm.cTableName = lcUsersTable oForm.nMaxAttempts = lnMaxAttempts oForm.cTableName = lcUsersTable oForm.SHOW() lnRtnVal = oForm.nRtnVal DO CASE CASE lnRtnVal = 0 MESSAGEBOX("Access granted") CASE lnRtnVal = 2 MESSAGEBOX("Max number of attempts reached, your account have been locked") CASE lnRtnVal = 3 MESSAGEBOX("User cancel login") CASE lnRtnVal = 4 MESSAGEBOX("Your account is locked") OTHERWISE MESSAGEBOX("Login failed") ENDCASE oForm.RELEASE() oForm = NULL IF lnRtnVal = 0 *Launch main app here, DO READ EVENTS, ETC.. ELSE *Do cleanup, clear events, etc... MESSAGEBOX("Good bye") ENDIF DEFINE CLASS Login AS FORM nRtnVal = 0 * 0 - Success * 1 - Password/UserName failed, but nMaxAttempts is set to unlimited * 2 - Max number of attempts reached * 3 - User Cancel * 4 - Account Locked * 5 - User not found cTableName = "" nNumberOfAttempts = 0 nMaxAttempts = 0 CONTROLBOX = .F. CAPTION = "Simple Login Screen" AUTOCENTER = .T. HEIGHT = 300 WIDTH = 370 MOVABLE = .T. BORDERSTYLE = 1 WindowType = 1 ADD OBJECT txtUser1 AS txtUser ADD OBJECT txtPassWord1 AS txtPassWord ADD OBJECT btnOk1 AS btnOk ADD OBJECT btnCancel1 AS btnCancel ADD OBJECT lblLabelUser1 AS lblLabelUser ADD OBJECT lblLabelCancel1 AS lblLabelPassWord PROCEDURE CheckMatch() LOCAL lcUserName, lcPassWord, lcUsersTable lcUsersTable = ALLTRIM(THISFORM.cTableName) lcUserName = ALLTRIM(THISFORM.txtUser1.VALUE) lcPassWord = ALLTRIM(THISFORM.txtPassWord1.VALUE) SELECT (lcUsersTable) SEEK ALLTRIM(lcUserName) ORDER TAG cUserName IF FOUND() &&UserName found, check for account locked IF NOT &lcUsersTable..lLocked IF ALLTRIM(&lcUsersTable..cUserPass) == lcPassWord lnRtnVal = 0 &&Access granted ELSE THISFORM.nNumberOfAttempts = THISFORM.nNumberOfAttempts + 1 IF THISFORM.nMaxAttempts <> 0 IF THISFORM.nNumberOfAttempts > THISFORM.nMaxAttempts lnRtnVal = 2 &&MAx attempts reached, lock account REPLACE &lcUsersTable..lLocked WITH .T. IN (lcUsersTable) ELSE lnRtnVal = 1 ENDIF ELSE &&Allow unlimited attempts lnRtnVal = 1 ENDIF ENDIF ELSE lnRtnVal = 4 &&Account is locked ENDIF ELSE lnRtnVal = 5 ENDIF RETURN lnRtnVal ENDPROC ENDDEFINE DEFINE CLASS lblLabelUser AS LABEL CAPTION = "User Name:" LEFT = 20 TOP = 60 AUTOSIZE = .T. ENDDEFINE DEFINE CLASS lblLabelPassword AS LABEL CAPTION = "Password:" LEFT = 20 TOP = 105 AUTOSIZE = .T. ENDDEFINE DEFINE CLASS txtUser AS TEXTBOX LEFT = 100 TOP = 55 HEIGHT = 25 WIDTH = 200 ENDDEFINE DEFINE CLASS txtPassWord AS TEXTBOX LEFT = 100 TOP = 100 HEIGHT = 25 WIDTH = 200 PASSWORDCHAR = "*" ENDDEFINE DEFINE CLASS btnOK AS COMMANDBUTTON CAPTION = '\<Ok' LEFT = 75 TOP = 200 HEIGHT = 25 PROCEDURE CLICK LOCAL lnRtnVal, lnAttemptsLeft lnRtnVal = THISFORM.CheckMatch() DO CASE CASE INLIST(lnRtnVal, 0, 2, 4) THISFORM.nRtnVal = lnRtnVal THISFORM.HIDE() CASE lnRtnVal = 5 MESSAGEBOX("Your UserName/Password combination is not in our database " + CHR(13) + "Try again or register.") OTHERWISE IF THISFORM.nMaxAttempts > 0 lnAttemptsLeft = THISFORM.nMaxAttempts - THISFORM.nNumberOfAttempts MESSAGEBOX("Invalid user name or password " + CHR(13) + "You have " + ALLTRIM(STR(lnAttemptsLeft)) + " attempt(s) left") ELSE MESSAGEBOX("Invalid user name or password " + CHR(13) + "Try again!") ENDIF *Let them try again ENDCASE ENDPROC ENDDEFINE DEFINE CLASS btnCancel AS COMMANDBUTTON CAPTION = '\<Cancel' LEFT = 200 TOP = 200 HEIGHT = 25 PROCEDURE CLICK THISFORM.nRtnVal = 3 THISFORM.HIDE() ENDPROC ENDDEFINE -
Tuesday, July 14, 2009 11:37 PM
What about :
DEFINE BAR 2 OF "POPUP" PROMPT " ----" SKIP FOR ;MUSERID="USERIDNAME"
Some times we need to declare muserid as public .
P.S.
DOCTOR TAMAR :
It is global by default it is in the first segement of APP. eveni don't declare it as global
azizsallam- Edited by abd el aziz sallam Friday, July 17, 2009 8:37 AM
-
Wednesday, July 15, 2009 9:35 PMAnswerer
Make it a property of the application object:
DEFINE BAR 2 OF "POPUP" PROMPT " ----" SKIP FOR goApp.mUserID = "USERIDNAME"
goApp does need to be declared in the main program and be private, but in my apps, it's the only variable that's not local.
Tamar
- Marked As Answer by Riquel_Dong Thursday, July 16, 2009 9:19 AM
-
Friday, July 24, 2009 2:18 AMthank you verry.
i wish happy, rich, funny reach to you -
Friday, July 24, 2009 2:18 AMthank you verry.
i wish happy, rich, funny reach to you -
Friday, July 24, 2009 2:19 AMthank you verry.
i wish happy, rich, funny reach to you -
Friday, July 24, 2009 2:19 AMthank you verry.
i wish happy, rich, funny reach to you -
Friday, July 24, 2009 2:19 AMthank you verry.
i wish happy, rich, funny reach to you

