I, an amateur, messed up again... The stuff I worked on today isn't co-operating, help?
-
Wednesday, September 12, 2012 4:54 AM
So, I am back to my fake log-in program, and added a "First run" feature (kinda) to it. When it starts, it asks what you want to do, press 1 for sign-up, 2 for sign-in, 3 to exit, and 4 if it is the first time it has been run (to create a save database).
I changed the exit set a bit so it would say "Thanks for using this program" then delay, and end the program.
I only added/changed my code today, and so I am not sure what might be the problem, however when you press 3 or 4, it says, "Press any key to continue...," as in, it isn't reading my code. Did I put something in the wrong place? I have looked all over and can't find anything. Here is my code, and beware it is a spaghetti code since I can't kick the habit, and don't know any alternatives: (Any and all help would be appreciated!)
TextWindowPlus.DisableCloseButton()
TextWindow.Title = "Sign-in"
TextWindowPlus.Top = 0
TextWindowPlus.Left = 0
TextWindowPlus.Height = 36
TextWindowPlus.Width = 100
counter = 0
CompName = PEInformation.CompName()
TextWindow.WriteLine("Welcome to " + CompName + "'s computer! Press '1' to sign-up; press '2' to sign-in; press '3' to exit, or press '4' if this is the first time you are running this program.")
opt = ""
opt = TextWindow.Read()
If opt = "1" Then
begin:
TextWindow.WriteLine("")
TextWindow.Write("Please enter your first name: ")
name = TextWindow.Read()
TextWindow.Write("Please create a username: ")
usrnm = TextWindow.Read()
TextWindow.Write("Please create a password: ")
HiddenCLIInput()
pass = HIPWStr
TextWindow.WriteLine("")
TextWindow.Write("Please confirm your password: ")
HiddenCLIInput()
pass3 = HIPWStr
If pass = pass3 then
TextWindow.WriteLine("")
File.InsertLine("C:\Login Info.txt", "1", name)
File.InsertLine("C:\Login Info.txt", "2", usrnm)
File.InsertLine("C:\Login Info.txt", "3", pass)
TextWindow.WriteLine("Press 1 if you would like to make another account; press 2 if you want to sign-in; or press 3 to quit program.")
opt2 = ""
opt2 = TextWindow.Read()
Else
TextWindow.WriteLine("Please try again, your password and confirmation didn't match.")
Goto begin
EndIf
If opt2 = "1" Then
Goto begin
ElseIf opt2 = "2" then
Goto begin2
ElseIf opt2 = "3" Then
Goto begin3
EndIf
ElseIf opt = "2" then
begin2:
TextWindow.WriteLine("")
TextWindow.Write("Please enter your name: ")
name2 = TextWindow.Read()
If name2 = File.ReadLine("C:\Login Info.txt", "1") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "2") and pass2 = File.ReadLine("C:\Login Info.txt", "3") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
If name2 = File.ReadLine("C:\Login Info.txt", "4") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "5") and pass2 = File.ReadLine("C:\Login Info.txt", "6") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
EndIf
If name2 = File.ReadLine("C:\Login Info.txt", "7") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "8") and pass2 = File.ReadLine("C:\Login Info.txt", "9") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
If name2 = File.ReadLine("C:\Login Info.txt", "10") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "11") and pass2 = File.ReadLine("C:\Login Info.txt", "12") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
ElseIf opt = "3" then
begin3:
TextWindow.Write("Thanks for using JOman's log-in program!")
Program.Delay(5000)
Program.End()
ElseIf opt = "4" Then
TextWindow.WriteLine("Since this is your first time running this program, I will need you to create a save directory for me.")
Program.Delay(1500)
TextWindow.WriteLine("First, please right-click on an open area on your desktop. On the menu that pops up, hover your cursor (mouse arrow) on 'New.'")
Program.Delay(1500)
TextWindow.WriteLine("Then click on 'Text Document.' Immediately type, ''Login Info'' and hit enter.")
Program.Delay(1500)
TextWindow.WriteLine("Third, open 'Computer' (Windows Vista and up) or 'My Computer' (Windows XP and older) by opening the Start menu on the lower left of the screen.")
Program.Delay(1500)
TextWindow.WriteLine("Now double-click on your 'C:\' drive to access the root of the computer. Don't mess with anything in here except for the next step, otherwise your computer may not work again.")
Program.Delay(1500)
TextWindow.WriteLine("Next, drag the 'Login Info.txt' file from your desktop into the window for your C:\ drive. You can now close the window.")
EndIf
EndIf
EndIF
EndIf
endif
'==============================================================='
' Hidden CLI Password Input by GoToLoop in March 2012 '
'==============================================================='
Sub HiddenCLIInput
'--- Accepts an input from the user w/o displaying what is being typed
'--- Returns HIPWStr as the string typed
'--- Accepts HIPWMax as maximum # of chars which HIPWStr can have
SpecialCharsHeader()
HiddenInputInit()
HiddenInputLoop()
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputInit
InitCursorX = TextWindow.CursorLeft
InitCursorY = TextWindow.CursorTop
If HIPWMax <= 0 Then ' Max # of chars which can be accepted from user
HIPWMax = 255 ' If HIPWMax is undetermined, use default 255
EndIf
HIPWKey = "" ' Typed char to be analysed
HIPWStr = "" ' Password result formed outta accepted HIPWKey chars
HiddenChars = "" ' Which HIPWStrDisplay derives from
HiddenChar = STAR ' Char displayed in place of what is being typed
EnterKey = CR ' Key to confirm the input
DeleteKey = BS ' Key to delete last char stored in HIPWStr
For num = 1 To HIPWMax
HiddenChars = HiddenChars + HiddenChar
EndFor
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputLoop
While HIPWKey <> EnterKey
HIPWKey = TextWindow.ReadKey() ' Waits next key to be hit
HiddenInputParse() ' Decides if it can be accept
HiddenInputHide() ' Replaces typed by HiddenChars
EndWhile
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputParse
HIPWKeyCode = Text.GetCharacterCode(HIPWKey)
If HIPWKeyCode >= 32 Then ' Tests if printable
HIPWStr = Text.Append(HIPWStr HIPWKey) ' Creates PW string
EndIf
HIPWStrLen = Text.GetLength(HIPWStr)
If HIPWStrLen > HIPWMax Then ' Checks if size passed limit
HIPWKey = DeleteKey
EndIf
If HIPWKey = DeleteKey Then ' Deletes last char typed
TextWindow.Write(SPC + BS + BS + SPC + BS + BEL)
HIPWStr = Text.GetSubText(HIPWStr 1 HIPWStrLen-1)
EndIf
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputHide
HIPWStrLen = Text.GetLength(HIPWStr)
HIPWStrDisplay = Text.GetSubText(HiddenChars 1 HIPWStrLen)
TextWindow.CursorLeft = InitCursorX ' Repositions cursor at the beginning
TextWindow.CursorTop = InitCursorY
TextWindow.Write(HIPWStrDisplay) ' to display HiddenChars
EndSub
'------------------------------------------------------------------------------------------------------------'
'==============================================================='
' Constant Header Includes '
'==============================================================='
Sub SpecialCharsHeader
' --- Initializes constants for special control characters in ASCII code:
BEL= Text.GetCharacter ( 7) ' Makes internal PC-Speaker buzz
BS= Text.GetCharacter ( 8) ' Backspace
TAB= Text.GetCharacter ( 9) ' Horizontal Tabulation (HT)
LF= Text.GetCharacter (10) ' Line-Feed (jumps a line)
CR= Text.GetCharacter (13) ' Carriage Return
ESC= Text.GetCharacter (27) ' Escape Key
CRS= Text.GetCharacter (22) ' Cursor
ARW= Text.GetCharacter (26) ' Right Arrow
QUO= Text.GetCharacter (34) ' Double Quotation Mark
SQU= Text.GetCharacter (166) ' Half Vertical Rectangle
APO= "'" ' Apostrophe
DOT= "." ' Period
COMMA= "," ' Comma
STAR= "*" ' Asterisk
SPC= " " ' SPaCe
EndSub
'------------------------------------------------------------------------------------------------------------'
'A computer without code is like a car without gasoline.'
'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'
- Edited by Joman Mied Wednesday, September 12, 2012 4:59 AM Because I wanted to change sentence structure a bit.
All Replies
-
Wednesday, September 12, 2012 9:19 AMYou could check the proper indentation by clicking with the right mousebutton, and then click on format the program. (in the editor). In that way you can see if the else etc. are in the right places. I haven't tried it with your program, but it can give you a good insight about the flow in the program.
Jan [ WhTurner ] The Netherlands
-
Wednesday, September 12, 2012 10:42 AMAnswerer
Hi again!
A long time ago, I was messing with that code above, but never finished it!
For now, I'm gonna publish that here in the state I've left it.
Only things still missing are LoadDB() & SaveDB() subroutines. The rest I guess it's working. :P
PS: It's complete now! :D
'_________________________________________________________________________'
' Login System Example (v1.5)
' Modularized Remix
' by GoToLoop (Sep/2012)
' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
'/thread/45a686fe-9e24-4c30-8919-1ec054ec6cc9
'_________________________________________________________________________'
'_________________________________________________________________________'
' Text Screen Init:
TextWindow.Title = "Login System"
TextWindow.ForegroundColor = "Yellow"
TextWindow.Left = (Desktop.Width - 80*8) / 2
TextWindow.Top = (Desktop.Height - 26*12) / 2
' Var & Database Init:
HIDDEN = "True" ' Password is hidden when being typed
LOAD = "False" ' Auto loads DB when program starts
SAVE = "False" ' Auto saves DB everytime it is modified
BACKUP = "True" ' Auto makes additional DB copies in a specified minute interval = bkpTimer
userMax = 10
passMax = 20
qustMax = 30
answMax = 20
SpecialCharsHeader()
SetDBPaths()
'_________________________________________________________________________'
Begin:
' User Choice:
While LOGGED <> "True"
Greetings()
choice = Text.ConvertToUpperCase( TextWindow.ReadKey() )
If choice = "1" Or choice = "L" Then
Login()
ElseIf choice = "2" Or choice = "R" Then
Register()
ElseIf choice = "3" Or choice = "D" Then
DisplayUsers()
ElseIf choice = "4" Or choice = "G" Then
Loading()
ElseIf choice = "5" Or choice = "S" Then
Saving()
ElseIf choice = "6" Or choice = "Q" Then
Quit()
EndIf
EndWhile
' Logged User:
While LOGGED
Welcome()
choice = Text.ConvertToUpperCase( TextWindow.ReadKey() )
If choice = "1" Or choice = "P" Then
EditPass()
ElseIf choice = "2" Or choice = "S" Then
EditQA()
ElseIf choice = "3" Or choice = "D" Then
EraseUser()
ElseIf choice = "4" Or choice = "L" Then
LogOff()
EndIf
EndWhile
Goto Begin
'_________________________________________________________________________'
' Constant Header Includes
'_________________________________________________________________________'
Sub SpecialCharsHeader
' --- Initializes constants for special control characters in ASCII code:
BEL = Text.GetCharacter ( 7) ' Makes internal PC-Speaker buzz
BS = Text.GetCharacter ( 8) ' Backspace
TAB = Text.GetCharacter ( 9) ' Horizontal Tabulation (HT)
LF = Text.GetCharacter (10) ' Line-Feed (jumps a line)
CR = Text.GetCharacter (13) ' Carriage Return
ESC = Text.GetCharacter (27) ' Escape Key
CRS = Text.GetCharacter (22) ' Cursor
ARW = Text.GetCharacter (26) ' Right Arrow
QUO = Text.GetCharacter (34) ' Double Quotation Mark
SQU = Text.GetCharacter (166) ' Half Vertical Rectangle
APO = "'" ' Apostrophe
DOT = "." ' Period
COMMA = "," ' Comma
COLON = ":" ' Colon
STAR = "*" ' Asterisk
SPC = " " ' SPaCe
EndSub
'_________________________________________________________________________'
' General Subroutine Section
'_________________________________________________________________________'
Sub Greetings
TextWindow.BackgroundColor = "Black"
TextWindow.Clear()
TextWindow.WriteLine("Welcome friend to our services!")
TextWindow.WriteLine("You can login to your account")
TextWindow.WriteLine("or then apply to register one:" + LF)
TextWindow.WriteLine("* <L> or <1> to Login")
TextWindow.WriteLine("* <R> or <2> to Register")
TextWindow.WriteLine("* <D> or <3> to Display")
TextWindow.WriteLine("* <G> or <4> to Get DB")
TextWindow.WriteLine("* <S> or <5> to Save DB")
TextWindow.WriteLine("* <Q> or <6> to Quit" + LF)
EndSub
'_________________________________________________________________________'
Sub Welcome
TextWindow.BackgroundColor = "DarkBlue"
TextWindow.Clear()
TextWindow.WriteLine(user + ", what do you want to do?")
TextWindow.WriteLine("Choose one of the options below:" + LF)
TextWindow.WriteLine("* <P> or <1> to change Password")
TextWindow.WriteLine("* <S> or <2> to change Secret")
TextWindow.WriteLine("* <D> or <3> to delete Account")
TextWindow.WriteLine("* <L> or <4> to execute Logoff" + LF)
EndSub
'_________________________________________________________________________'
Sub GetUserList
userList = Array.GetAllIndices(reg)
userNumber = Array.GetItemCount (userList)
EndSub
'_________________________________________________________________________'
Sub DisplayUsers
GetUserList()
If userNumber = 0 Then
TextWindow.WriteLine(LF + "No users registered yet!" + BEL)
Else
TextWindow.WriteLine("Registered User List:" + LF)
EndIf
For i = 1 To userNumber
TextWindow.Write(i + ARW + SPC)
TextWindow.Write(userList[i] + TAB)
EndFor
TextWindow.WriteLine(LF)
TextWindow.Pause()
TextWindow.WriteLine("")
EndSub
'_________________________________________________________________________'
Sub AskConfirm
TextWindow.WriteLine("Hit <Y> or <Enter> to go ahead,")
TextWindow.WriteLine("or any other key to go back!" + LF)
key = Text.ConvertToUpperCase( TextWindow.ReadKey() )
If key = "Y" Or key = CR Then
OK = "True"
ElseIf key = ESC Then
Quit()
Else
OK = "False"
EndIf
EndSub
'_________________________________________________________________________'
Sub Quit
If BACKUP Then
BackUpDB()
EndIf
Sound.PlayBellRingAndWait()
Program.End()
EndSub
'_________________________________________________________________________'
' User's Credential Input Subroutine Section
'_________________________________________________________________________'
Sub AskCredentials
For i = 0 To 0 Step 0
TextWindow.WriteLine("Username: (Max. " + userMax + " chars)")
user = Text.GetSubText(TextWindow.Read() 1,userMax)
If user = "" Then
EmptyInputErrMsg()
Else
AskPass()
EndIf
EndFor
EndSub
'_________________________________________________________________________'
Sub AskPass
TextWindow.WriteLine("Password: (Max. " + passMax + " chars)")
If HIDDEN Then
HIPWMax = passMax
HiddenCLIInput()
pass = HIPWStr
Else
pass = Text.GetSubText(TextWindow.Read() 1,passMax)
EndIf
If pass = "" Then
EmptyInputErrMsg()
ElseIf user = pass Then
SameInputErrMsg()
Else
TextWindow.WriteLine("")
i = 1
EndIf
EndSub
'_________________________________________________________________________'
Sub AskSecret
For i = 0 To 0 Step 0
TextWindow.WriteLine("Type in custom question: (Max. " + qustMax + " chars)")
question = Text.GetSubText(TextWindow.Read() 1,qustMax)
If question = "" Then
EmptyInputErrMsg()
ElseIf question = user Then
SameUserQuestionErrMsg()
Else
TextWindow.WriteLine("Type in secret answer: (Max. " + answMax + " chars)")
answer = Text.ConvertToLowerCase(Text.GetSubText(TextWindow.Read() 1,answMax))
If answer = "" Then
EmptyInputErrMsg()
ElseIf question = answer Then
SameInputErrMsg()
Else
TextWindow.WriteLine("")
i = 1
EndIf
EndIf
EndFor
EndSub
'_________________________________________________________________________'
Sub EmptyInputErrMsg
TextWindow.WriteLine(LF + "You've just entered a blank input!")
TextWindow.WriteLine("Try again!!!" + LF + BEL)
EndSub
'_________________________________________________________________________'
Sub SameInputErrMsg
TextWindow.WriteLine(LF + "They can't be equal!")
TextWindow.WriteLine("Try again!!!" + LF + BEL)
EndSub
'_________________________________________________________________________'
Sub SameUserQuestionErrMsg
TextWindow.WriteLine(LF + "Custom question can't be the same as username!")
TextWindow.WriteLine("Try again!!!" + LF + BEL)
EndSub
'_________________________________________________________________________'
' Register Subroutine Section
'_________________________________________________________________________'
Sub Register
TextWindow.WriteLine(LF + "You are about to register for a new account." + LF)
AskConfirm()
If OK Then
CreateAcc()
EndIf
EndSub
'_________________________________________________________________________'
Sub CreateAcc
TextWindow.BackgroundColor = "DarkRed"
TextWindow.Clear()
AskCredentials()
If Array.ContainsIndex(reg, user) Then
TextWindow.Write ("Account " + QUO + user + QUO)
TextWindow.WriteLine(" exists already!!!" + LF + BEL)
Else
SecretAcc()
ConfirmAcc()
EndIf
TextWindow.Pause()
EndSub
'_________________________________________________________________________'
Sub SecretAcc
TextWindow.WriteLine(LF + "If you later forget this account's password,")
TextWindow.WriteLine("you can recover it answering correctly")
TextWindow.WriteLine("to a custom question you create below..." + LF)
AskSecret()
EndSub
'_________________________________________________________________________'
Sub ConfirmAcc
TextWindow.Clear()
TextWindow.WriteLine("Username: " + TAB + user)
TextWindow.WriteLine("Password: " + TAB + pass)
TextWindow.WriteLine("Question: " + TAB + question)
TextWindow.WriteLine("Answer: " + TAB + answer + LF)
AskConfirm()
If OK Then
reg[user]["pass"] = pass
reg[user]["question"] = question
secret[question] = answer
If SAVE Then
SaveDB()
EndIf
TextWindow.Write ("ACCOUNT " + QUO + user + QUO)
TextWindow.WriteLine(" CREATED SUCCESSFULLY!!!" + LF)
Sound.PlayChimes()
Else
TextWindow.WriteLine("ACCOUNT CREATION CANCELLED!!!" + LF + BEL)
EndIf
EndSub
'_________________________________________________________________________'
' Login Subroutine Section
'_________________________________________________________________________'
Sub Login
TextWindow.BackgroundColor = "DarkGreen"
TextWindow.Clear()
AskCredentials()
If Array.ContainsIndex(reg, user) Then
If pass = reg[user]["pass"] Then
AuthorizeAccess()
Else
TextWindow.WriteLine("PASSWORD MISMATCH!!!" + LF + BEL)
TextWindow.WriteLine("Wanna try to recover it?" + LF)
AskConfirm()
If OK Then
Recover()
EndIf
EndIf
Else
TextWindow.Write ("Sorry! No such " + QUO + user + QUO)
TextWindow.WriteLine(" account exists!" + LF + BEL)
TextWindow.Pause()
EndIf
EndSub
'_________________________________________________________________________'
Sub AuthorizeAccess
TextWindow.WriteLine("ACCESS GRANTED!!!" + LF)
TextWindow.WriteLine("Welcome " + user + " !" + LF)
TextWindow.Title = "Logged as " + user
Sound.PlayChime()
TextWindow.Pause()
LOGGED = "True"
EndSub
'_________________________________________________________________________'
Sub LogOff
TextWindow.WriteLine("Are you sure you want to logoff?" + LF)
AskConfirm()
If OK Then
SignOut()
EndIf
EndSub
'_________________________________________________________________________'
Sub SignOut
TextWindow.Title = "No User Logged Now!"
LOGGED = "False"
EndSub
'_________________________________________________________________________'
Sub Recover
For i = 0 To 0 Step 0
TextWindow.BackgroundColor = "DarkMagenta"
TextWindow.Clear()
TextWindow.Write ("In order to recover password for account ")
TextWindow.WriteLine(QUO + user + QUO + COMMA)
TextWindow.WriteLine("please answer the following question:" + LF)
pass = reg[user]["pass"]
question = reg[user]["question"]
TextWindow.WriteLine(question)
answer = Text.ConvertToLowerCase( TextWindow.Read() )
If answer = secret[question] Then
TextWindow.WriteLine("PASSWORD RECOVERED SUCCESSFULLY!!!" + LF)
TextWindow.WriteLine("Username = " + user)
TextWindow.WriteLine("Password = " + pass + LF)
Sound.PlayChimes()
i = 1
TextWindow.WriteLine("Wanna use it to login right way?" + LF)
AskConfirm()
If OK Then
AuthorizeAccess()
EndIf
Else
TextWindow.WriteLine("WRONG ANSWER!!!" + LF + BEL)
TextWindow.WriteLine("Wish to attempt once more?" + LF)
AskConfirm()
If OK <> "True" Then
i = 1
EndIf
EndIf
EndFor
EndSub
'_________________________________________________________________________'
' Edit Subroutine Section
'_________________________________________________________________________'
Sub EditPass
TextWindow.BackgroundColor = "DarkCyan"
TextWindow.Clear()
TextWindow.WriteLine("Current Password = " + reg[user]["pass"] + LF)
TextWindow.Write ("Type in new password below")
TextWindow.WriteLine(" and confirm it afterwards..." + LF)
i=0
AskPass()
If pass = reg[user]["pass"] Then
TextWindow.Write ("You've chosen same password")
TextWindow.WriteLine(" as previous one!" + LF + BEL)
ElseIf i <> 0 Then
AskConfirm()
If OK Then
reg[user]["pass"] = pass
If SAVE Then
SaveDB()
EndIf
TextWindow.WriteLine("PASSWORD CHANGED SUCCESSFULLY!!!" + LF)
TextWindow.WriteLine("Username = " + user)
TextWindow.WriteLine("Password = " + pass + LF)
Sound.PlayChimes()
Else
TextWindow.WriteLine("PASSWORD CHANGING PROCEDURE CANCELLED!!!" + LF + BEL)
EndIf
Else
TextWindow.WriteLine("ERROR CHANGING PASSWORD!!!" + LF)
EndIf
TextWindow.Pause()
EndSub
'_________________________________________________________________________'
Sub EditQA
TextWindow.BackgroundColor = "DarkCyan"
TextWindow.Clear()
TextWindow.WriteLine("Current Custom Question = " + reg[user]["question"])
TextWindow.Write ("Current Secret Answer = ")
TextWindow.WriteLine( secret[reg[user]["question"]] + LF)
TextWindow.Write ("Type in new question and answer,")
TextWindow.WriteLine(" then confirm them afterwards..." + LF)
AskSecret()
If question = reg[user]["question"] Then
TextWindow.WriteLine("New Question = Old Question!" + LF + BEL)
ElseIf answer = secret[ reg[user]["question"] ] Then
TextWindow.WriteLine("New Answer = Old Answer!" + LF + BEL)
Else
AskConfirm()
If OK Then
reg[user]["question"] = question
secret[question] = answer
If SAVE Then
SaveDB()
EndIf
TextWindow.WriteLine("BOTH QUESTION & ANSWER CHANGED!!!" + LF)
TextWindow.WriteLine(APO + question + APO + LF + QUO + answer + QUO + LF)
Sound.PlayChimes()
Else
TextWindow.WriteLine("Q&A CHANGING PROCEDURE CANCELLED!!!" + LF + BEL)
EndIf
EndIf
TextWindow.Pause()
EndSub
'_________________________________________________________________________'
Sub EraseUser
TextWindow.BackgroundColor = "DarkGray"
TextWindow.Clear()
TextWindow.Write ("BEWARE! You're about to delete ")
TextWindow.WriteLine(QUO + user + QUO + " username account!")
TextWindow.WriteLine("This procedure cannot be undone!!!" + LF)
TextWindow.WriteLine("Retype your password if you're OK with it..." + LF)
i = 0
AskPass()
If i <> 0 And pass = reg[user]["pass"] Then
secret[ reg[user]["question"] ] = ""
reg[user] = ""
If SAVE Then
SaveDB()
EndIf
SignOut()
TextWindow.WriteLine("ACCOUNT " + QUO + user + QUO + " ERASED!!!" + LF)
Sound.PlayMusic("T160 O1 L30 GF# FE# D# DC# D# DFE# R")
Else
TextWindow.WriteLine("ACCOUNT ERASING PROCEDURE CANCELLED!!!" + LF + BEL)
EndIf
TextWindow.Pause()
EndSub
'_________________________________________________________________________'
' Hidden CLI Password Input Section:
'_________________________________________________________________________'
Sub HiddenCLIInput
'--- Accepts an input from the user w/o displaying what is being typed
'--- Returns HIPWStr as the string typed
'--- Accepts HIPWMax as maximum # of chars which HIPWStr can have
HiddenInputInit()
HiddenInputLoop()
EndSub
'_________________________________________________________________________'
Sub HiddenInputInit
InitCursorX = TextWindow.CursorLeft
InitCursorY = TextWindow.CursorTop
If HIPWMax <= 0 Then ' Max # of chars which can be accepted from user
HIPWMax = 255 ' If HIPWMax is undetermined, use default 255
EndIf
HIPWKey = "" ' Typed char to be analysed
HIPWStr = "" ' Password result formed outta accepted HIPWKey chars
HiddenChars = "" ' Which HIPWStrDisplay derives from
HiddenChar = STAR ' Char displayed in place of what is being typed
EnterKey = CR ' Key to confirm the input
DeleteKey = BS ' Key to delete last char stored in HIPWStr
For num = 1 To HIPWMax
HiddenChars = HiddenChars + HiddenChar
EndFor
EndSub
'_________________________________________________________________________'
Sub HiddenInputLoop
While HIPWKey <> EnterKey
HIPWKey = TextWindow.ReadKey() ' Waits next key hit
HiddenInputParse() ' Decides if it can be accepted
HiddenInputHide() ' Replaces typed chars by HiddenChars
EndWhile
EndSub
'_________________________________________________________________________'
Sub HiddenInputParse
HIPWKeyCode = Text.GetCharacterCode(HIPWKey)
If HIPWKeyCode >= 32 Then ' Tests if printable
HIPWStr = Text.Append(HIPWStr HIPWKey) ' Creates PW string
EndIf
HIPWStrLen = Text.GetLength(HIPWStr)
If HIPWStrLen > HIPWMax Then ' Checks if size exceeded limit
HIPWKey = DeleteKey
EndIf
If HIPWKey = DeleteKey Then ' Deletes last char typed
TextWindow.Write(SPC + BS + BS + SPC + BS + BEL)
HIPWStr = Text.GetSubText(HIPWStr 1 HIPWStrLen-1)
EndIf
EndSub
'_________________________________________________________________________'
Sub HiddenInputHide
HIPWStrLen = Text.GetLength(HIPWStr) ' Obtain PW string current size
HIPWStrDisplay = Text.GetSubText(HiddenChars 1 HIPWStrLen)
TextWindow.CursorLeft = InitCursorX ' Repositions cursor at the beginning
TextWindow.CursorTop = InitCursorY
TextWindow.Write(HIPWStrDisplay) ' to display HiddenChars
EndSub
'_________________________________________________________________________'
'_________________________________________________________________________'
' Load/Save Login Database Subroutine Section
'_________________________________________________________________________'
Sub SetDBPaths
dir1 = "DB\"
dir2 = "Bkp\"
file1 = "Login"
file2 = "Q&A"
ext1 = ".db"
ext2 = ".bkp"
ERR = "FAILED"
bkpTimer = 15 ' interval in minutes
path = Program.Directory + "\"
path1 = path + dir1 + file1 + ext1
path2 = path + dir1 + file2 + ext1
If SAVE Then
File.CreateDirectory(path + dir1)
EndIf
If LOAD Then
LoadDB()
EndIf
If BACKUP Then
File.CreateDirectory(path + dir2)
Timer.Tick = BackUpDB
Timer.Interval = bkpTimer * 60 * 1000 ' minutes -> milliseconds
EndIf
EndSub
'_________________________________________________________________________'
Sub Loading
TextWindow.WriteLine(LF + "Loading from disk..." + LF)
LoadDB()
TextWindow.WriteLine("Done!" + LF)
Sound.PlayClickAndWait()
EndSub
'_________________________________________________________________________'
Sub LoadDB
reg = File.ReadContents(path1)
secret = File.ReadContents(path2)
If reg = "" Or secret = "" Then
DiskLoadErrMsg()
EndIf
EndSub
'_________________________________________________________________________'
Sub Saving
AskConfirm()
If OK Then
TextWindow.WriteLine(LF + "Saving into disk..." + LF)
SaveDB()
TextWindow.WriteLine("Done!" + LF)
Sound.PlayClick()
TextWindow.Pause()
EndIf
EndSub
'_________________________________________________________________________'
Sub SaveDB
CheckEmptyDB()
If OK Then
If File.WriteContents(path1 reg)=ERR Or File.WriteContents(path2 secret)=ERR Then
DiskSaveErrMsg()
EndIf
Else
EmptyDBErrMsg()
EndIf
EndSub
'_________________________________________________________________________'
Sub BackUpDB
Date = Clock.Date
Hour = Clock.Hour
Min = Clock.Minute
path3 = path + dir2 + Date + "\"
path4 = path3 + file1 + ".[" + Hour + "-" + Min + "]" + ext1 + ext2
path5 = path3 + file2 + ".[" + Hour + "-" + Min + "]" + ext1 + ext2
CheckEmptyDB()
If OK Then
File.CreateDirectory(path3)
If File.WriteContents(path4 reg)=ERR Or File.WriteContents(path5 secret)=ERR Then
DiskBackUpErrMsg()
EndIf
Else
EmptyDBErrMsg()
EndIf
EndSub
'_________________________________________________________________________'
Sub CheckEmptyDB
If reg = "" Or secret = "" Then
OK = "False"
Else
OK = "True"
EndIf
EndSub
'_________________________________________________________________________'
Sub EmptyDBErrMsg
TextWindow.WriteLine(LF + "WARNING: Login database empty!" + LF + BEL)
EndSub
'_________________________________________________________________________'
Sub DiskLoadErrMsg
TextWindow.WriteLine(LF + "WARNING: Failed to load database from disk!" + LF + BEL)
TextWindow.Pause()
EndSub
'_________________________________________________________________________'
Sub DiskSaveErrMsg
TextWindow.WriteLine(LF + "WARNING: Failed to save database to disk!" + LF + BEL)
EndSub
'_________________________________________________________________________'
Sub DiskBackUpErrMsg
TextWindow.WriteLine(LF + "WARNING: Failed to save backup to disk!" + LF + BEL)
TextWindow.PauseWithoutMessage()
EndSub
'_________________________________________________________________________'
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Wednesday, September 12, 2012 10:42 AM
- Edited by GoToLoopEditor Wednesday, September 12, 2012 11:10 AM
- Edited by GoToLoopEditor Wednesday, September 12, 2012 11:39 AM
- Edited by GoToLoopEditor Wednesday, September 12, 2012 8:14 PM Complete Program!
- Edited by GoToLoopEditor Wednesday, September 12, 2012 8:56 PM Complete Program!
- Edited by GoToLoopEditor Thursday, September 13, 2012 12:19 AM Complete Program
-
Wednesday, September 12, 2012 8:31 PMAnswerer
Finally finished this login program! Besides "Load" & "Save", a "Backup" feature as well!
Whole DB is comprised by 2 arrays using dictionary/hash/map indices:
- 2D reg[user] w/ fields ["pass"] & ["question"]
- 1D secret[question], in which question = reg[user]["question"]
They are saved as Login.db & Q&A.db inside DB sub-folder located in same folder as executable runs.
That's all folks!
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
-
Wednesday, September 12, 2012 11:45 PM
Turns out I had to move an "EndIf" from opt = "2" to the end of opt = "3" because it was excluding opt = "3" from the "If" statement.
Now it works great!
'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'
- Marked As Answer by Joman Mied Wednesday, September 12, 2012 11:45 PM
-
Thursday, September 20, 2012 8:10 AM
Thanks for the help Everyone!
When I try to run the code below in the Small Basic compiler, I get the error
message; "Cannot Find object 'TextWindowPlus" Why is this?Best regards,
CyberSpaceman
TextWindowPlus.DisableCloseButton()
TextWindow.Title = "Sign-in"
TextWindowPlus.Top = 0
TextWindowPlus.Left = 0
TextWindowPlus.Height = 36
TextWindowPlus.Width = 100
counter = 0
CompName = PEInformation.CompName()
TextWindow.WriteLine("Welcome to " + CompName + "'s computer! Press '1' to sign-up; press '2' to sign-in; press '3' to exit, or press '4' if this is the first time you are running this program.")
opt = ""
opt = TextWindow.Read()
If opt = "1" Then
begin:
TextWindow.WriteLine("")
TextWindow.Write("Please enter your first name: ")
name = TextWindow.Read()
TextWindow.Write("Please create a username: ")
usrnm = TextWindow.Read()
TextWindow.Write("Please create a password: ")
HiddenCLIInput()
pass = HIPWStr
TextWindow.WriteLine("")
TextWindow.Write("Please confirm your password: ")
HiddenCLIInput()
pass3 = HIPWStr
If pass = pass3 then
TextWindow.WriteLine("")
File.InsertLine("C:\Login Info.txt", "1", name)
File.InsertLine("C:\Login Info.txt", "2", usrnm)
File.InsertLine("C:\Login Info.txt", "3", pass)
TextWindow.WriteLine("Press 1 if you would like to make another account; press 2 if you want to sign-in; or press 3 to quit program.")
opt2 = ""
opt2 = TextWindow.Read()
Else
TextWindow.WriteLine("Please try again, your password and confirmation didn't match.")
Goto begin
EndIf
If opt2 = "1" Then
Goto begin
ElseIf opt2 = "2" then
Goto begin2
ElseIf opt2 = "3" Then
Goto begin3
EndIf
ElseIf opt = "2" then
begin2:
TextWindow.WriteLine("")
TextWindow.Write("Please enter your name: ")
name2 = TextWindow.Read()
If name2 = File.ReadLine("C:\Login Info.txt", "1") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "2") and pass2 = File.ReadLine("C:\Login Info.txt", "3") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
If name2 = File.ReadLine("C:\Login Info.txt", "4") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "5") and pass2 = File.ReadLine("C:\Login Info.txt", "6") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
EndIf
If name2 = File.ReadLine("C:\Login Info.txt", "7") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "8") and pass2 = File.ReadLine("C:\Login Info.txt", "9") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
If name2 = File.ReadLine("C:\Login Info.txt", "10") then
TextWindow.Write("Please enter username: ")
usrnm2 = TextWindow.Read()
TextWindow.Write("Please enter your password: ")
HiddenCLIInput()
pass2 = HIPWStr
TextWindow.WriteLine("")
If usrnm2 = File.ReadLine("C:\Login Info.txt", "11") and pass2 = File.ReadLine("C:\Login Info.txt", "12") then
TextWindow.Write("Hi "+ name2 + ", your access is granted!")
Program.Delay(2000)
Program.End()
Else
TextWindow.WriteLine("Sorry, wrong credentials.")
counter = counter + 1
If counter < 3 then
Goto begin2
Elseif counter = 3 then
TextWindow.Write("You have exceeded your login attempts.")
Program.Delay(3000)
Program.End()
EndIf
endif
ElseIf opt = "3" then
begin3:
TextWindow.Write("Thanks for using JOman's log-in program!")
Program.Delay(5000)
Program.End()
ElseIf opt = "4" Then
TextWindow.WriteLine("Since this is your first time running this program, I will need you to create a save directory for me.")
Program.Delay(1500)
TextWindow.WriteLine("First, please right-click on an open area on your desktop. On the menu that pops up, hover your cursor (mouse arrow) on 'New.'")
Program.Delay(1500)
TextWindow.WriteLine("Then click on 'Text Document.' Immediately type, ''Login Info'' and hit enter.")
Program.Delay(1500)
TextWindow.WriteLine("Third, open 'Computer' (Windows Vista and up) or 'My Computer' (Windows XP and older) by opening the Start menu on the lower left of the screen.")
Program.Delay(1500)
TextWindow.WriteLine("Now double-click on your 'C:\' drive to access the root of the computer. Don't mess with anything in here except for the next step, otherwise your computer may not work again.")
Program.Delay(1500)
TextWindow.WriteLine("Next, drag the 'Login Info.txt' file from your desktop into the window for your C:\ drive. You can now close the window.")
EndIf
EndIf
EndIF
EndIf
endif
'==============================================================='
' Hidden CLI Password Input by GoToLoop in March 2012 '
'==============================================================='
Sub HiddenCLIInput
'--- Accepts an input from the user w/o displaying what is being typed
'--- Returns HIPWStr as the string typed
'--- Accepts HIPWMax as maximum # of chars which HIPWStr can have
SpecialCharsHeader()
HiddenInputInit()
HiddenInputLoop()
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputInit
InitCursorX = TextWindow.CursorLeft
InitCursorY = TextWindow.CursorTop
If HIPWMax <= 0 Then ' Max # of chars which can be accepted from user
HIPWMax = 255 ' If HIPWMax is undetermined, use default 255
EndIf
HIPWKey = "" ' Typed char to be analysed
HIPWStr = "" ' Password result formed outta accepted HIPWKey chars
HiddenChars = "" ' Which HIPWStrDisplay derives from
HiddenChar = STAR ' Char displayed in place of what is being typed
EnterKey = CR ' Key to confirm the input
DeleteKey = BS ' Key to delete last char stored in HIPWStr
For num = 1 To HIPWMax
HiddenChars = HiddenChars + HiddenChar
EndFor
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputLoop
While HIPWKey <> EnterKey
HIPWKey = TextWindow.ReadKey() ' Waits next key to be hit
HiddenInputParse() ' Decides if it can be accept
HiddenInputHide() ' Replaces typed by HiddenChars
EndWhile
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputParse
HIPWKeyCode = Text.GetCharacterCode(HIPWKey)
If HIPWKeyCode >= 32 Then ' Tests if printable
HIPWStr = Text.Append(HIPWStr HIPWKey) ' Creates PW string
EndIf
HIPWStrLen = Text.GetLength(HIPWStr)
If HIPWStrLen > HIPWMax Then ' Checks if size passed limit
HIPWKey = DeleteKey
EndIf
If HIPWKey = DeleteKey Then ' Deletes last char typed
TextWindow.Write(SPC + BS + BS + SPC + BS + BEL)
HIPWStr = Text.GetSubText(HIPWStr 1 HIPWStrLen-1)
EndIf
EndSub
'------------------------------------------------------------------------------------------------------------'
Sub HiddenInputHide
HIPWStrLen = Text.GetLength(HIPWStr)
HIPWStrDisplay = Text.GetSubText(HiddenChars 1 HIPWStrLen)
TextWindow.CursorLeft = InitCursorX ' Repositions cursor at the beginning
TextWindow.CursorTop = InitCursorY
TextWindow.Write(HIPWStrDisplay) ' to display HiddenChars
EndSub
'------------------------------------------------------------------------------------------------------------'
'==============================================================='
' Constant Header Includes '
'==============================================================='
Sub SpecialCharsHeader
' --- Initializes constants for special control characters in ASCII code:
BEL= Text.GetCharacter ( 7) ' Makes internal PC-Speaker buzz
BS= Text.GetCharacter ( 8) ' Backspace
TAB= Text.GetCharacter ( 9) ' Horizontal Tabulation (HT)
LF= Text.GetCharacter (10) ' Line-Feed (jumps a line)
CR= Text.GetCharacter (13) ' Carriage Return
ESC= Text.GetCharacter (27) ' Escape Key
CRS= Text.GetCharacter (22) ' Cursor
ARW= Text.GetCharacter (26) ' Right Arrow
QUO= Text.GetCharacter (34) ' Double Quotation Mark
SQU= Text.GetCharacter (166) ' Half Vertical Rectangle
APO= "'" ' Apostrophe
DOT= "." ' Period
COMMA= "," ' Comma
STAR= "*" ' Asterisk
SPC= " " ' SPaCe
EndSub- Edited by CyberSpaceman Thursday, September 20, 2012 8:11 AM
-
Thursday, September 20, 2012 11:09 AM
Your question has been answered in another one of your posts.
http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/c4d75ea5-b3a1-4da4-aa7a-e7935154c7ba
I am not sure what extension this command is from but make sure the .dll file for the extension is in the same directory as the program you are running.
-
Friday, September 21, 2012 12:37 AMDo you have the Data extension?
'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'

