Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    May 2012
    Posts
    64

    Unanswered: Login Form that doesn't require password just name

    I want to build a login form for my database that doesn't ask for a password, just a name. The reason is I really won't have a problem with security, but I want each entry to have an author listed in case we need to know who did it. I don't want the user to have to select their name on every entry but just log in once when opening the program and then have that name saved. How can I do this? If I keep the login form open then I believe I can figure it out, but I would really like the login form to disappear after selecting a user.

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    In that situation I generally use Environ("UserName") to trap the windows login and store it as a variable in the main form. As you said, it doesn't offer anything for security but it will let you know who was in the application. Usually, I'll create a user table to convert their username to their real name and then display this info in the form footer so they know.

    Steve

  3. #3
    Join Date
    May 2012
    Posts
    64
    Quote Originally Posted by sps View Post
    In that situation I generally use Environ("UserName") to trap the windows login and store it as a variable in the main form. As you said, it doesn't offer anything for security but it will let you know who was in the application. Usually, I'll create a user table to convert their username to their real name and then display this info in the form footer so they know.
    How would I do that? The only way I could think of would be to add a column in my inventory table for the username and add a field for it on the form in the header. On that field, where would I put Environ("UserName")? In the VBA editor? But in which event?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or better yet use the network API call to retrrieve the network logon ID, and other attributes if you so wish
    Environ can be easily spoofed, the network API's are a lot harder to circumvent
    Google dev ashish API
    or look through the code bank here for stuff posted by PKStormy
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    May 2012
    Posts
    64
    How would I go about using the network API call? I understand what you are saying but I really don't understand how to implement either of these options.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off do a google (oddly enough the google searches should also give you guidnace on how to use the API calls)
    find the code
    then cut and paste that code and put it in a public module
    the n call the functions as required

    if you want to take it a bit further, and use workgroup security (a bit of a misnomer as its easy enough to circumvent.
    add thiose network logons to your workgroups file,m assing them to the cirrect user groups. then as and when you need to do a check on security permissions use the correct ADO library (think its the ADOX security library) query the woirkgroupo and find out if the specified logon is a memebr of the specified work group and has the required permission to do the requested action.
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Just to go back and answer how to implement the simply environ version (which may not be the most secure form but if you're looking for easy implementation it's a valid option.)

    You can implement this in a few ways, but a good combination of usefulness and simplicity is to put it right on your main form (assuming it's always open when you do your database updates) and access it when needed.

    Steps:
    1) Add the username text field (txtUserName) and make sure it is locked so the user can't edit it.
    2) In the On Open or On Load form events set the text box to the username (txtUserName.value = environ("UserName"))
    3) Whenever you need it just reference the text box value

    You can also just add the environ("UserName") inline whenever you need it but in my company our usernames are numbers so I prefer to decode them to actual names. Generally I'll add one extra table, User, with UserName and DisplayName fields. I then create a public function to set userName & displayName variables from this database table based on their network username. I prefer to use these variables rather than a text box. This way, if you want to upgrade to API calls or another method in the future you only have to change the code that sets the variables and everything else will continue to work. Also, it gives the flexibility of choosing the actual user name or the display name as needed.

    Steve

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    why use environ, when the API call does the same functionality?

    granted you need to copy some code into a common module, but after that you call the function as you would environ

    why use something that cannot be trusted for something such as security (or at least as good as Access security can get.

    the bells and whistles of assigning thoise userids to the wrokgroiup fiel and then querying later can come at a later date.

    There are some good uses of environ (one being to find temporary workspace / scratch file location and so on... soemething that cannot get screwed up if the network fails).

    but why consider using something as flaky as environ when there are perfectly acceptable alternatives that don't require much more effort.
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Just for simplicity. For my needs, the only purpose of this is to know who made a change. It's an internal application and I'm not concerned about security. That is also why I separate the Username lookup into a function, if I ever decide I need the extra security the API calls provide then I can just change the function. This is just a simple solution to meet a simple need, what advantage does the API call have when the user could just press F11, open the table and change the value?

    Steve

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    when there is a better solution available already I don't see the point in starting off with bad practice. worst case scenario, use environ, then decide to reuse it (becuase their is a belief that the environ is 'the right' way to go.

    if the API calls were a PITA to set up I'd agree, use environ for a quick and dirty fix, but recognise it as being a quick and dirty fix.
    I'd rather be riding on the Tiger 800 or the Norton

  11. #11
    Join Date
    May 2012
    Posts
    64
    Okay, I decided to use the environ method due to simplicity. However, I would like to save that username in my table so that each entry will have an author. I have a field in my table called Author which I have added to my new entry form. On my main navigation form that will always be open I have called the username using environ. How do I automatically fill the author field on my newItem form from the user name on my main form?

  12. #12
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    I would pull this out of your main form and create a public getAuthor function in a module. Call this function whenever you need the username.

    This way, you can change any of the implementation of how you get the username without impacting the rest of your application. You could decide to store it in a variable, look it up each time, switch from the environ to the API technique or anything else you want. As long as you continue to return the username from the function everything else will continue to work.

    Then simply set the Author text box value on the new item form to the results of getAuthor() whenever the form is opened or whenever you start a new record

    Steve

  13. #13
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Quote Originally Posted by klpe237 View Post
    Okay, I decided to use the environ method due to simplicity. However, I would like to save that username in my table so that each entry will have an author. I have a field in my table called Author which I have added to my new entry form. On my main navigation form that will always be open I have called the username using environ. How do I automatically fill the author field on my newItem form from the user name on my main form?
    Just a note here...

    Pulling the PC's logon name is only good if you have an NT network setup wherever the database is. Where I'm working at the moment, we just have a couple of central QNAP servers, and the PC's are just regular PC's that you'd have at home.

    There's no restrictions, and no community login. If that's the case (if not now, maybe at some point in the future, if/when you move to a new company) then using someone else's PC for the day, means that you'd be logging on as that user, and not your own.

    Similarly with network API. If the network isn't setup to use network logins, then that's of no use either.


    My two cents:
    For sheer diversity I would create a simple login form that is loaded with an AutoExec macro. I would also get the macro to hide the ribbon, status bar, navigation bar, absolutely everything, except the small login form... The form simply asks for a username, or even better, has a combo box with a list of users names they can simply pick from... Once selected, the user clicks the 'Login' button next to the combo box, and their specific ribbon can be loaded, their custom navigation sidebar, their specific form (if they have one), or obviously keep various bits hidden if that's what you want.

    That way you can transport your database to anywhere you want, even without a network infrastructure setup, and your logins will still work, just as before.

    I just posted a pretty large post on another thread: http://www.dbforums.com/microsoft-ac...-database.html - Which was concerned more about security, but things like hiding the ribbon, sidebar, etc. are all covered, as well as setting up an AutoExec Macro.


    Just thought you'd want to know a more durable and transportable method of implementing your design wishes.


    Hope this helps!


    PS: As for using an author, I would simply have a module (called Global Vars, or something similar) stored on the client itself. The module would just look like:

    Code:
    Global LOGGED_USER As String
    When the 'Login' button is pushed on your login form, then along with the other user specific login script, you add the line:

    Code:
    LOGGED_USER = Me.YourComboBoxName.Value
    Then whenever you want to use the authors name for anything else in the database, you simply use (for example - this will change the label 'SomeLabel' to show the username):

    Code:
    Me.SomeLabel.Caption = LOGGED_USER

    This is simple, takes a couple of seconds to setup, doesn't require querying any database tables (which you want to avoid if possible for performance reasons) or creating record sets, nor does it require making additional function calls, all of which will drain resources, quite unnecessarily.

    It's much more efficient to use a global variable, and as it's stored on the client (front-end), then it won't effect any other users. Also, as there's no other way to proceed past the login form without selecting a user, then there is no way that LOGGED_USER can fail to be set, or called incorrectly (as Global variables are always available to all objects), meaning that you won't have to error handle or troubleshoot, which is definitely a possibility with using additional functions, third-party API's or Environmental calls (which are OS specific too).

    Put simply, it will just work, and be incredibly efficient, without the possibility of failing/erroring.
    Last edited by kez1304; 06-29-12 at 08:42.
    Looking for the perfect beer...

  14. #14
    Join Date
    May 2012
    Posts
    64
    how do I create a public getAuthor function in a module? I'm not sure what a module is or how to make it public?

  15. #15
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Quote Originally Posted by klpe237 View Post
    how do I create a public getAuthor function in a module? I'm not sure what a module is or how to make it public?
    Just use a Global Variable.

    Getter and setter methods aren't really necessary outside of Class Modules, as you're not really using the object orientated features of Access unless creating classes (okay, not strictly true, but for all intensive purposes [getter/setter methods and variable security] that's true).


    Best way to go with sps' suggestion.

    1) Create a Macro, call it 'AutoExec'.
    2) For the Macro's code, type the following:
    Code:
    LOGGED_USER = (Environ$("Username"))
    3) Save it.
    4) Push ALT+F11
    5) Insert -> Module
    6) Click the Save button, and name the new module - Global Vars
    7) At the very top of the code area, copy and paste:
    Code:
    Global LOGGED_USER As String
    8) Save it.
    9) Close down Access.
    10) Open Access.

    Now, everytime you open this access client, it'll automatically store your username in the LOGGED_USER variable. Anytime you want to save, display, print, whatever that username, simply type in VBA:

    Code:
    Me.SomeObjectOrControl.Value = LOGGED_USER
    Or, for example, as a default value for a textbox:

    Code:
    =LOGGED_USER

    And you're done. No need for getter or setter functions. No need to manually store the logged on user in some table somewhere.
    Last edited by kez1304; 06-29-12 at 09:36.
    Looking for the perfect beer...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •