UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Preserve User Login Info?, Access 2010    
 
   
Kiron
post Jul 23 2020, 05:25 AM
Post#1



Posts: 12
Joined: 3-October 19



Hope you all are safe.
I have user table as image attached. I have another table named tblStaus containing several fields regarding work status. I want to preserve last login info like UserName in tblStatus. How do I develop this. Im using this code
CODE
Me![DateModified].Value = Now()
on event procedure of Submit button to preserve last update timestamp. But can't develop to preserve login User name. Please help me. Thank in advance. Stay safe...
Attached File(s)
Attached File  tblUsers.jpg ( 26.31K )Number of downloads: 0
 
Go to the top of the page
 
isladogs
post Jul 23 2020, 07:05 AM
Post#2


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


When the user logs in, save the contents of that form control as a global variable e.g. strUserName.
Create a public function in a standard module to retrieve it

CODE
Public Function GetUserName()

GetUserName=Nz(strUserName, "")

End Function


You can then retrieve that by typing GetUserName anywhere in your application

As an alternative, you can use tempvars instead of a global variable.

As an aside, for security, any passwords stored in your application should be securely encrypted using RC4 or another similar approach.
Using a password mask provides no protection at all.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
DanielPineault
post Jul 23 2020, 07:55 AM
Post#3


UtterAccess VIP
Posts: 7,430
Joined: 30-June 11



I do as isladogs suggested, but another approach some developer use if to use a login form and simply hide it. Then they can reference the form anytime they want and access username, password, ... (it's a form so you control what it makes available to you)

--------------------
Daniel Pineault (2010-2020 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
cheekybuddha
post Jul 23 2020, 09:27 AM
Post#4


UtterAccess Moderator
Posts: 13,120
Joined: 6-December 03
From: Telegraph Hill


Public Dunction ...

ohyeah.gif

--------------------


Regards,

David Marten
Go to the top of the page
 
isladogs
post Jul 23 2020, 09:35 AM
Post#5


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


Thanks David. Now corrected. Please do continue to spellcheck my posts 😃

P.S. You'll be pleased to know the House Martins (definitely not Martens) are still doing their aerial acrobatics here.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
BruceM
post Jul 23 2020, 10:15 AM
Post#6


UtterAccess VIP
Posts: 8,157
Joined: 24-May 10
From: Downeast Maine


I would save it as a TempVar, which is directly accessible, including in queries.

If the user name is the same as the Windows login you can use the Environ function:

Environ("username")

Some people see a potential security risk with the use of Environ, and prefer APIs for that reason, but I believe that if the Environ function presents a risk it is because the code is accessible rather than it being an inherent problem with Environ.
Go to the top of the page
 
isladogs
post Jul 23 2020, 10:46 AM
Post#7


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


The issue with using Environ is that user names can be 'spoofed'.
I wouldn't use APIs either due to the usual issue with 'bitness'..

In my opinion, a better alternative to both of those is WScript
CODE
CreateObject("WScript.Network").UserName

Much simpler than the API code, works in both bitnesses and cannot be spoofed.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
BruceM
post Jul 23 2020, 11:04 AM
Post#8


UtterAccess VIP
Posts: 8,157
Joined: 24-May 10
From: Downeast Maine


I've heard that about Environ, but do not understand how it would happen unless the code itself is compromised. In any case, your method is quite tidy and compact.
Go to the top of the page
 
isladogs
post Jul 23 2020, 11:07 AM
Post#9


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


I don't want to publicise how its done in an open forum.
However, if you send me a PM, I will explain how easy it is to do.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
Kiron
post Jul 26 2020, 02:10 AM
Post#10



Posts: 12
Joined: 3-October 19



So many thanks @isladogs. By the way I am not expert in coding. I have made the form using following codes collected from different forum.
CODE
Private Sub Cancel_Click()
Me.Undo
DoCmd.Close
End Sub

Private Sub Index_AfterUpdate()
Dim Index As String
Dim stLinkCriteria As String
NewIndex = Me.Index.Value
stLinkCriteria = "[Index] = " & "'" & NewIndex & "'"
If Me.Index = DLookup("[Index]", "tblCADProposal", stLinkCriteria) Then
    MsgBox "This Index, " & NewIndex & ", already exists in database." _
    & vbCr & vbCr & "Please check Index again Or contact the Administrator", vbInformation, "Duplicate Name"
    Me.Undo
End If
End Sub

Private Sub Submit_Click()
On Error GoTo ErrHandler:
If IsNull(Index) Then
   MsgBox "You have not entered information to submit!", , "No Info"
  'check the UserName, LoginID or Password field is not emtry before insert to database
ElseIf IsNull(Index) Or IsNull(PropRecDate) Or IsNull(PropRefNo) Then
   MsgBox "The Index, Proposal Receive Date and Reference No fields are required", , "Required Field"
Else
   Msg1 = "Do you want to submit these information?"
   Style = vbYesNo + vbCritical
   Title = "Data Submitted"
   Response = MsgBox(Msg1, Style, Title)
   If Response = vbYes Then
     'Submit information and go for new record
          DoCmd.Save
          DoCmd.GoToRecord , , acNewRec
          Me.Index.SetFocus
     Exit Sub
   End If
   If Response = vbNo Then
   'Cancel submit information and close the registration form
      Me.Undo
      DoCmd.Close
      Exit Sub
    End If
End If
Exit_ErrHandler:
Exit Sub
ErrHandler:
    MsgBox Err.Description, vbCritical
    Err.Clear
End Sub
. I have added a field named 'UserLogin' in table "tblCADProposal". Where should I use your suggest coding. If possible please give me details coding and instructions.
Thanks in advance.
Go to the top of the page
 
isladogs
post Jul 26 2020, 03:49 AM
Post#11


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


Hi Kiron
Its not clear to me which code you are referring to in my various posts.

In case it helps, I have a complete working app that you are welcome to use: Password Login

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
Kiron
post Jul 26 2020, 04:25 AM
Post#12



Posts: 12
Joined: 3-October 19



@isladogs. Thanks for reply. You suggest me following code in this thread
CODE
Public Function GetUserName()

GetUserName=Nz(strUserName, "")

End Function
. where should I implement in the form using following code
CODE
Private Sub Cancel_Click()
Me.Undo
DoCmd.Close
End Sub

Private Sub Index_AfterUpdate()
Dim Index As String
Dim stLinkCriteria As String
NewIndex = Me.Index.Value
stLinkCriteria = "[Index] = " & "'" & NewIndex & "'"
If Me.Index = DLookup("[Index]", "tblCADProposal", stLinkCriteria) Then
    MsgBox "This Index, " & NewIndex & ", already exists in database." _
    & vbCr & vbCr & "Please check Index again Or contact the Administrator", vbInformation, "Duplicate Name"
    Me.Undo
End If
End Sub

Private Sub Submit_Click()
On Error GoTo ErrHandler:
If IsNull(Index) Then
   MsgBox "You have not entered information to submit!", , "No Info"
  'check the UserName, LoginID or Password field is not emtry before insert to database
ElseIf IsNull(Index) Or IsNull(PropRecDate) Or IsNull(PropRefNo) Then
   MsgBox "The Index, Proposal Receive Date and Reference No fields are required", , "Required Field"
Else
   Msg1 = "Do you want to submit these information?"
   Style = vbYesNo + vbCritical
   Title = "Data Submitted"
   Response = MsgBox(Msg1, Style, Title)
   If Response = vbYes Then
     'Submit information and go for new record
          DoCmd.Save
          DoCmd.GoToRecord , , acNewRec
          Me.Index.SetFocus
     Exit Sub
   End If
   If Response = vbNo Then
   'Cancel submit information and close the registration form
      Me.Undo
      DoCmd.Close
      Exit Sub
    End If
End If
Exit_ErrHandler:
Exit Sub
ErrHandler:
    MsgBox Err.Description, vbCritical
    Err.Clear
End Sub
Go to the top of the page
 
isladogs
post Jul 26 2020, 05:05 AM
Post#13


UtterAccess VIP
Posts: 2,468
Joined: 4-June 18
From: Somerset, UK


As far as I can see, your code doesn't appear to include the relevant part so I can't add it.

In your login form, do you have a textbox or combobox in which the user enters their username?
If so, you need to add code in the after update event of that control

CODE
Private Sub txtUserName_AfterUpdate()
strUserName=Me.txtUserName
End Sub


Then you need to add the GetUserName function already supplied o a standard module
In the declarations section at the top of that module you also need to add the line
CODE
Public strUserName As String



--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
AlbertKallal
post Jul 26 2020, 05:05 PM
Post#14


UtterAccess VIP
Posts: 3,123
Joined: 12-April 07
From: Edmonton, Alberta Canada


Well, once you get the logon information?

You can save/place that information in a plane jane public variable (just declare the variables at the module level in a non forms code module).

At that point, you can use the values.

What about errors re-setting variables?

Well, just always for production deploy a compiled accDE. All local and global variables ALWAYS BUT ALWAYS remain intact for the session (the time that the application was launched until shut down).

And becuase local and global variables NEVER lose their settings with a accDE? Then just general over all code runs much better. And any kind of settings like users or status, or connection strings etc.? They remain in full effect - even for un-handled errors.

And if you using the free run-time? Well again with a accDE, then any un-handled error does not matter and will not shut down the runtime. If you use a accDB (no compiled), then even just ONE stray error?
You will blow out your global variables, and worse if you using runtime? Then the whole application shuts down.

With an accDE? You don't' experience a shutdown, and you never will see your local or global vars re-set. This includes say a simple loop on a recordset, and you hit some null value. Now in place of a boom and a error? And your recordset going out of scope? Nope, the application just keeps on running like a un-stoppable fright train.

So, using an accDE not only fixes and allows you to keep global variables (like user logged on) intact, but they never fail, and this includes that of un-handled errors that often can occur (even in applications with extensive error handling). So until such time you have the time and skills to really do a great job in regards to error handling? Just always as a rule deploy a accDE - and that issue/problem is eliminated.

Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada



Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    5th August 2020 - 05:40 AM