Raspberry BASIC > Programming Challenges

GUI Login

<< < (4/4)

John Spikowski:
Nim Update

I had to rename the db_sqlite open/close procs to sqlopen/sqlclose to prevent a naming conflict with niup.


--- Code: Text ---# Nim 1.0.4 / IUP 3.28 - Login - JRS import niupimport niupextimport db_sqliteimport osimport md5 var initdb:bool = existsFile("user.db")let usrdb = sqlopen("user.db", "", "", "")if initdb == false:  usrdb.exec(sql"CREATE TABLE user (UserID VARCHAR NOT NULL, Password VARCHAR NOT NULL, CONSTRAINT user_pk PRIMARY KEY (UserID));") var uidtxt,showpwd,pwdtxt1,pwdtxt2,errlbl,zbtxt,newusr,loginbut:PIhandlevar newusr_cb:string proc Init_Form() =  Hide(errlbl)  SetAttribute(uidtxt, "VALUE", "")  SetAttribute(pwdtxt1, "VALUE", "")  SetAttribute(pwdtxt2, "VALUE", "")  SetAttribute(showpwd, "VALUE", "OFF")  SetAttribute(newusr, "VALUE", "OFF")  SetAttribute(zbtxt, "VALUE", "pwdtxt1")  SetAttribute(loginbut, "TITLE", "Login")  newusr_cb = "OFF"  SetFocus(uidtxt) proc login_clicked(ih:PIhandle):cint {.cdecl.}=  var uid:cstring  var pswd:cstring  uid = GetAttribute(uidtxt,"VALUE")  if GetAttribute(showpwd, "VALUE") == "OFF":    pswd = GetAttribute(pwdtxt1,"VALUE")  else:    pswd = GetAttribute(pwdtxt2,"VALUE")  # *** NEW USER ***  if newusr_cb == "ON":    if uid != "" and pswd != "":      let rtnmsg = usrdb.tryInsertId(sql"INSERT INTO user (UserID, Password) VALUES (?, ?)", uid, getMD5($pswd))      if rtnmsg == -1:        SetAttribute(errlbl, "TITLE", "Duplicate User ID")        Show(errlbl)        SetFocus(uidtxt)        return IUP_DEFAULT      Message("Login",  "User Added")      Init_Form()      return    else:      Show(errlbl)      SetFocus(uidtxt)      return IUP_DEFAULT   # *** LOGIN VERIFY ***  SetAttribute(errlbl, "TITLE", "User ID / Password Incorrect")  let dbpw = usrdb.getValue(sql"SELECT Password FROM user WHERE UserID=?", uid)  if dbpw != "":    if dbpw == getMD5($pswd):      Hide(errlbl)      Message("Login",  "Login Successful")      Init_Form()      return IUP_DEFAULT  Show(errlbl)  SetFocus(uidtxt)  return IUP_DEFAULT proc show_password(ih:PIhandle; state: bool):cint {.cdecl.}=  var pwd1,pwd2:cstring  if state:    pwd1 = GetAttribute(pwdtxt1,"VALUE")    SetAttribute(pwdtxt2, "VALUE", pwd1)    SetAttribute(zbtxt, "VALUE", "pwdtxt2")  else:    pwd2 = GetAttribute(pwdtxt2,"VALUE")    SetAttribute(pwdtxt1, "VALUE", pwd2)    SetAttribute(zbtxt, "VALUE", "pwdtxt1")    return IUP_DEFAULT proc new_user(ih:PIhandle; state: bool):cint {.cdecl.}=  if state:    newusr_cb = "ON"    SetAttribute(loginbut, "TITLE", "Add User")  else:    newusr_cb = "OFF"    SetAttribute(loginbut, "TITLE", "Login")  return IUP_DEFAULT # *** MAIN *** Open() # *** DIALOG ***var dlg = Create("dialog")SetAttributes(dlg,  "TITLE=\"Login\", " &  "SIZE=200x200, " &  "MAXBOX=NO, " &  "MINBOX=NO, " &  "RESIZE=NO, " &  "DEFAULTENTER=\"loginbut\"") # *** CONTAINER ***var vb = Create("vbox") # *** IMAGE ***var hb1 = Create("hbox")var piclbl = Create("label")SetAttributes(piclbl,  "IMAGE=\"login.png\", " &  "EXPAND=HORIZONTAL, " &  "ALIGNMENT=ACENTER:ATOP")discard Append(hb1, piclbl)discard Append(vb, hb1) # *** ERROR ***var hb2 = Create("hbox")errlbl = Create("label")SetAttributes(errlbl,  "TITLE=\"User ID / Password Incorrect\", " &  "FGCOLOR=\"#ff0000\", " &  "EXPAND=HORIZONTAL, " &  "ALIGNMENT=ACENTER")Hide(errlbl)discard Append(hb2, errlbl)discard Append(vb, hb2) # *** ENTRY ***var hb3 = Create("hbox")SetAttributes(hb3,  "MARGIN=20x10, " &  "GAP=5")var vb1 = Create("vbox")SetAttribute(vb1, "GAP", "15")var uidlbl = Create("label")SetAttribute(uidlbl, "TITLE", "User ID")discard Append(vb1, uidlbl)var pwdlbl = Create("label")SetAttribute(pwdlbl, "TITLE", "Password")discard Append(vb1, pwdlbl)discard Append(hb3, vb1)var vb2 = Create("vbox")uidtxt = Create("text")SetAttribute(uidtxt, "SIZE", "85x")discard Append(vb2, uidtxt)pwdtxt1 = Create("text")SetAttributes(pwdtxt1,  "PASSWORD=YES, " &  "SIZE=85x")pwdtxt2 = Create("text")SetAttribute(pwdtxt2, "SIZE", "85x")SetHandle("pwdtxt1", pwdtxt1)SetHandle("pwdtxt2", pwdtxt2)zbtxt = Zbox(pwdtxt1, pwdtxt2, nil)SetHandle("zbtxt", zbtxt)discard Append(vb2, zbtxt)discard Append(hb3, vb2)discard Append(vb, hb3) # *** SHOW/HIDE ***var hb4 = Create("hbox")SetAttributes(hb4,  "MARGIN=35x, " &  "GAP=40")showpwd = Create("toggle")SetAttributes(showpwd,  "TITLE=\"Show Password\", " &  "CANFOCUS=NO")newusr = Create("toggle")SetAttributes(newusr,  "TITLE=\"New User\", " &  "CANFOCUS=NO")discard Append(hb4, showpwd)discard Append(hb4, newusr)discard Append(vb, hb4) # *** LOGIN ***var hb5 = Create("hbox")SetAttribute(hb5, "MARGIN", "40x10")loginbut = Create("button")SetAttributes(loginbut,  "TITLE=\"Login\", " &  "EXPAND=HORIZONTAL")SetHandle("loginbut", loginbut)discard Append(hb5, loginbut)discard Append(vb, hb5) # *** ATTACH CONTAINER ***discard Append(dlg, vb) # *** CALLBACKS ***SetCallback(loginbut, "ACTION", login_clicked)SetCallback(showpwd, "ACTION", show_password)SetCallback(newusr, "ACTION", new_user) # *** PROCESS ***Show(dlg)MainLoop()sqlclose(usrdb)Close() 

ubuntu@rpi4b:~/guilc/nim-dev$ scriba showdb.sb
John   -   0b7efaa91a48ccd6c1dd58e3d69ea1a0
AIR   -   4de6ff4050222c488aa16286c39a605b
ubuntu@rpi4b:~/guilc/nim-dev$


Note: The screenshots are the same as the latest ScriptBasic submission.

AIR:
So how are your NIM adventures going, John?

Sorry I haven't been around lately - 14 hour days at work while moving into a new home doesn't leave a lot of time for anything...

AIR.

John Spikowski:
Hi AIR,

Glad you chimed in with an update of what is going on. I have been wrapping up some health issues and seem to be getting back to my old self. I just picked up a project and won't have much time for fun programming for a bit. I'm going to try an use Nim as part of the solution.

jalih:
Hi all,

I have been busy beta testing next version of 8th. JUCE based gui is out and the new gui is Nuklear based. I have to say, I like it more than JUCE based gui.

Sorry to hear John that you don't have much time for fun programming. I just started writing this!  ;D

John Spikowski:
I got things setup here. It's now up to the forum members to make it work.

We all have to eat and pay bills before heading to the sandbox.

Navigation

[0] Message Index

[*] Previous page

Go to full version