473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Storing the username of the Windows user

Seth Schrock
2,965 Expert 2GB
My plan is to use the username of the user that is logged into Windows to filter the data in my forms (record access control). I need to know the best way to store the username.

My understanding of public variables that aren't inside any sub or function is that any value assigned to them is retained until the database closes. My thinking is that I could obtain the current username and assign it to some variable when the database first opens and then use this variable as my filter for any form that needs filtered.

The other option that I see is to have a local table (not in the BE) that could store the username and then empty it when the database closed so that there would only ever be one username in it. The username could then be obtained from the table whenever needed.

Not sure if this would decrease performance, but I could also just pull the username each time I needed it and not store it at all (I'm planning on using the Environ("Username") function to get the username).

I'm sure that I could get any of these methods to work, but getting it to work doesn't mean that it is the best way.
Jan 14 '13 #1

✓ answered by NeoPa

A link to what Z is referring to (Function to Return UserName (NT Login) of Current User). He makes a good point ;-)

As for how best to store the value when retrieved, I believe Temp Vars in A2010 is the best way if available. Otherwise, a table could be used but you'd need to ensure the value is reset whenever the project starts to avoid spoofing. A way I often use (as I still work mainly in A2003) is to store it in a form that stays open throughout the project. Visible or otherwise is irrelevant. I then also have a Global variable which I check for contents before accessing. If the variable contains a ZLS (Zero Length String) I make sure it is reloaded from the form.

This extra level of checking is because a project can be reset in many ways while in use and that would reset all variables, but not the data on forms or in your tables.

PS. We cross-posted Seth, but I believe I have answered all your questions anyway :-)

6 2003
zmbd
5,501 Expert Mod 4TB
Seth,
A few ways to do this and in v2010 you now have the temp variables to store information. I have used a table as you've suggested, forms, class modules, and global variables (what you're calling a public variable). Each has their advantage and disadvantages... one such is that a global variable can loose its value in some cases.

As for obtaining the user name, the environment variable can be spoofed if a user knows how... there is an api call (you should be able to find it with a search here... I'm not at work where I can pull that code today) that is a tad more secure.
Jan 14 '13 #2
Seth Schrock
2,965 Expert 2GB
I found the api to get the user name. I have no worries about my users having the knowledge to change the user name, but I like to get into the habit of coding my databases to the best solution, not just one that works.

Now that you mention that global variables can loose their value, I think that I have heard that before. So, it seems that I'm down to either calling for the username each time I need it or storing it in a table. My guess would be that it would require less resources and allow for faster load times of my forms if I store it in a table. I would then use DLookup() to get it when needed instead of running the api all over again. Would this be correct?
Jan 14 '13 #3
NeoPa
32,556 Expert Mod 16PB
A link to what Z is referring to (Function to Return UserName (NT Login) of Current User). He makes a good point ;-)

As for how best to store the value when retrieved, I believe Temp Vars in A2010 is the best way if available. Otherwise, a table could be used but you'd need to ensure the value is reset whenever the project starts to avoid spoofing. A way I often use (as I still work mainly in A2003) is to store it in a form that stays open throughout the project. Visible or otherwise is irrelevant. I then also have a Global variable which I check for contents before accessing. If the variable contains a ZLS (Zero Length String) I make sure it is reloaded from the form.

This extra level of checking is because a project can be reset in many ways while in use and that would reset all variables, but not the data on forms or in your tables.

PS. We cross-posted Seth, but I believe I have answered all your questions anyway :-)
Jan 14 '13 #4
Seth Schrock
2,965 Expert 2GB
As I am using A2010, tempvars are available so I will try to learn how to use them. I think I have found a website that tells me all I need to know, but if I end up having trouble, I will post back in another thread.

Thanks Z and NeoPa for your help. It is very much appreciated.
Jan 14 '13 #5
NeoPa
32,556 Expert Mod 16PB
Always a pleasure Seth :-)

I believe TempVars were introduced in A2010 specifically in order to handle the problem where data stored in variables are all reset when any unhandled bug occurs in the project. Depending on the setting of when to break in the VBE options, this will prompt with buttons either to End or Debug. End causes the project to be reset. If no break occurs then this happens anyway.
Jan 14 '13 #6
zmbd
5,501 Expert Mod 4TB
I knew I should have checked the insights!
Yes the link Neopa provided mirrors what I use.

As for my prefered (as earlier versions didn't have the temp var collection) I like the "form" method. Makes it nice during alpha and beta testing as I can leave the form visible and verify that certain things are set as expected. Also, I include a timer function that checks for activity and a flag to soft or hard logoff users... not nearly as indepth as others have posted here for such - but it works.
Jan 14 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: yabba | last post by:
Is there a way to supply a nt/windows user/password combo in a url for an automatic login to a nt user/password secured site? Something like http://mysite.comuser=mepassword=mypassword =...
2
by: Erik | last post by:
I'm trying to get the login name for the user, and this is the code I use: string userName = WindowsIdentity.GetCurrent().Name; This works fine when the program is launched locally or...
8
by: Pete Wittig | last post by:
Hello, I am wondering if it is possible to create a networked application with C# that is seen as a windows user. For example, if Bob logged onto windows and then started the application, any...
4
by: Ferdinand Zaubzer | last post by:
With System.Security.Principal.WindowsIdentity.GetCurrent().Name I get the user name of the current Windows user. But how can I get the full name? Thanks Ferdinand
6
by: lanem | last post by:
Is it possible for me to get the actual windows user account that a user is logged in on their computer as? If they are logged on and authenticated on my network, can I get that username from my...
1
by: Jared | last post by:
Hi For some time now I have been looking for some client side script to get the windows logon id. My asp.net application is running across three domains, so windows authentication is no use...
7
by: Marc Solé | last post by:
Hello all, I have a web application that runs in a server and makes a Windows user validation to loggin. My question is, how can I get that loggin user, password and domanin to use it in my...
0
by: neddy | last post by:
Hi All, I am new to web services programming and have the following business requirement which I would appreciate help with. Scenario: All users log onto Windows machine with standard Windows...
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
5
by: Max2006 | last post by:
Hi, I am trying to limit my wcf service endpoint to response to only given windows user or group. How can I do that? Is there any way to configure that in the .config file? Thank you, Max
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.