fb:porticula NoPaste
Very simple login menu example
| Uploader: | Sebastian |
| Datum/Zeit: | 10.05.2009 21:03:13 |
' Very simple login menu example (Created: May 10, 2009)
'
' FreeBASIC 0.20.0
'
' WARNING: Usernames and passwords are stored without using any encryption.
' Therefore, they can be read as plain text (e.g. using Notepad)!
' This program is distributed in the hope that it will be useful, but WITHOUT
' ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
' FOR A PARTICULAR PURPOSE.
FUNCTION HiddenInput() AS STRING
DIM AS STRING S="", Key
DIM AS INTEGER z1, s1
z1 = CSRLIN
s1 = POS(CSRLIN)
DO
DO
SLEEP 1
Key = INKEY
LOOP UNTIL Key <> ""
Select Case Asc(Key)
Case 8
If Len(S) > 0 Then
LOCATE z1, s1: PRINT STRING(LEN(S)," ")
S = LEFT(S,LEN(S)-1)
LOCATE z1, s1: PRINT STRING(LEN(S),"*")
Else
Beep
End If
Case 10, 13
Return S
Case 27
Return ""
Case 32 to 255
S += Key
LOCATE z1, s1: PRINT STRING(LEN(S),"*")
End Select
Loop
END FUNCTION
TYPE tAccount
Username As String
Password As String
END TYPE
DIM AS INTEGER f, i=0, found=0
DIM AS STRING Usr, Pwd, YN
REDIM AS tAccount Accounts(0)
CLS
f=FREEFILE
INPUT "Create new account? [y/n] ", YN
IF UCASE(YN) = "Y" Then
INPUT "Username: ", Usr
INPUT "Password: ", Pwd
OPEN "password.txt" FOR APPEND AS #f
WRITE #f, Usr, Pwd
CLOSE #f
PRINT "Your account was created. Press any key to quit."
Sleep: End
End If
IF OPEN ("password.txt" FOR INPUT AS #f) = 0 THEN 'File exists
DO UNTIL EOF(f)
ReDim Preserve Accounts(i)
Input #f, Accounts(i).Username, Accounts(i).Password
i += 1
LOOP
CLOSE #f
CLS
PRINT "Enter your login data:"
INPUT "Username: ", Usr
PRINT "Password: ";
Pwd = HiddenInput()
PRINT: PRINT
For i = LBOUND(Accounts) To UBOUND(Accounts)
If Accounts(i).Username <> "" Then
If Accounts(i).Username = Usr And Accounts(i).Password = Pwd Then
found = 1
End If
End If
Next i
If found = 1 Then
Color 10
Print "Login successful. Press any key to quit."
Else
Color 12
Print "Login failed."
End If
Color 7
Else
Print "Failure: Access data file is empty."
End If
Sleep: End



FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!



