473,804 Members | 3,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Log-In Form in Access 2007

4 New Member
hi there
First of all, I'm very glad that I found this big online comunity. I hope I will find the answer for my problem.
It might have been asked before so please excuse me if so.

So I have to create a logon form to connect to a database

the database has a table called "users" where the user_id, username and password for each user is stored.

I'm having trouble solving the authentication part where the user and password typed in form is compared with the values stored in table records. I didn't use a combox to select the user in the form, I used two textboxes, first for username and second from password. I've added one button for validating the authentication. As I recall, I have to put the solution at the "on click" event for this button.

So everyone who wants to log in must type both the user name and password into the fom and the press the button :). Please point to a solution for validating the authentication.
Other information I can provide
User_ID field's type is number
Username and Password fields' type is text


What's the easiest way to match the data typed in the form with the values in table records?

Please answer with the VBA code. Thanks in advance
May 14 '10 #1
9 6010
gabrielro
4 New Member
nobody knows ? :( please help
May 15 '10 #2
NeoPa
32,579 Recognized Expert Moderator MVP
Gabriel, we don't work here by providing ready made solutions. If you're looking for someone to do your work for you then I'm afraid you're in the wrong place. Also, posting bumps to a thread before at least 24 hours has elapsed is unlikely to win you any new friends here. Some people only get on during the working week. None of us feel it appropriate to have a questioner try to hurry us along with a bump so soon.

That said, if you are willing to learn, and want help in that direction, you will find many here willing and able to assist you.

-Administrator.
May 15 '10 #3
NeoPa
32,579 Recognized Expert Moderator MVP
What you're asking for is essentially pretty simple. The code behind your Command Button simply searches through the [Users] table for a record that matches the [UserName] on your form. It then checks the [Password] value against the value entered on the form.

You can most easily use DLookup() to get the password value from the table.

I would suggest some sort of encryption routine to use for storing and comparing the passwords. It won't work any better, but if you're storing the passwords in a table it would be pretty easy to find the passwords from there.
May 15 '10 #4
gabrielro
4 New Member
You're right. I apologize for the reply posted in such short time after starting the topic. I have very little programming experience in VBA. In fact this project I'm working requires basic ms access knowledge. I just try to come up with something more thorough. It's the first time I use VBA actually.
Can I post VBA code I thought it should do the trick? To get maybe some new hints? I thought about Dlookup too but sadly I can't figure out the right criteria for my problem :( I'm a total newb maybe that's the reason.
May 16 '10 #5
NeoPa
32,579 Recognized Expert Moderator MVP
It's perfectly acceptable to post your code (ensure you enclose it in the code tags), but it must have a valid matching question.

For DLookup(), you'd need something along the lines of :
Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria As String
  2.  
  3. strCriteria = "(([UserName]='%U') AND ([Password]='%P'))"
  4. strCriteria = Replace(strCriteria, "%U", Me.txtUserName)
  5. strCriteria = Replace(strCriteria, "%P", Me.txtPassword)
  6. If IsNull(DLookup("[User_ID]", _
  7.                   "[Users]", _
  8.                   strCriteria)) Then
  9.   Call MsgBox("Your message here")
  10.   'Some code to exit or retry
  11. End If
  12. 'This is where the code runs that relies on a valid user
May 17 '10 #6
NeoPa
32,579 Recognized Expert Moderator MVP
If you chose to use encryption of some form then line #5 would change to :
Expand|Select|Wrap|Line Numbers
  1. strCriteria = Replace(strCriteria, "%P", Scramble(Me.txtPassword, True))
I include a boilerplate encryption routine that has a security rating of just above sea-level. You are welcome to use it as-is, or even change it or put a totally new one in. Clearly, any passwords saved should be saved after they have been processed via the same routine as you use on your form. This one is two-way (allowing reversal of encryption) but the process would work equally well with one-way only encryption routines.
Expand|Select|Wrap|Line Numbers
  1. 'If I told you what this did I'd have to kill you.
  2. Public Function Scramble(strPW As String, _
  3.                          Optional ByVal blnEncrypt = False) As String
  4.     Dim intIdx As Integer, intChr As Integer
  5.     Dim strChr As String, strHi As String, strLo As String
  6.  
  7.     If strPW = "" Then Exit Function
  8.     If Not blnEncrypt Then
  9.         If Left(strPW, 1) < "4" _
  10.         Or Left(strPW, 1) > "7" _
  11.         Or Len(strPW) < 4 _
  12.         Or (Len(strPW) Mod 2) = 1 Then
  13.             blnEncrypt = True
  14.         Else
  15.             For intIdx = 2 To Len(strPW)
  16.                 strChr = UCase(Mid(strPW, intIdx, 1))
  17.                 If (strChr < "0" Or strChr > "9") _
  18.                 And (strChr < "A" Or strChr > "F") Then
  19.                     blnEncrypt = True
  20.                     Exit For
  21.                 End If
  22.             Next intIdx
  23.         End If
  24.     End If
  25.     If blnEncrypt Then
  26.         Scramble = Left(Hex(Asc(Environ("Path"))), 1)
  27.         For intIdx = 1 To Len(strPW)
  28.             Scramble = Scramble & _
  29.                        Right(UCase(Hex(Not Asc(Mid(strPW, intIdx, 1)))), 2)
  30.         Next intIdx
  31.         Scramble = Scramble & Right(Hex(Asc(Environ("Path"))), 1)
  32.     Else
  33.         For intIdx = 2 To Len(strPW) - 2 Step 2
  34.             strHi = UCase(Mid(strPW, intIdx, 1))
  35.             strLo = UCase(Mid(strPW, intIdx + 1, 1))
  36.             intChr = IIf(strHi > "9", Asc(strHi) - &H36, Val(strHi)) * &H10
  37.             intChr = intChr + IIf(strLo > "9", Asc(strLo) - &H37, Val(strLo))
  38.             Scramble = Scramble & Chr(&HFF And (Not intChr))
  39.         Next intIdx
  40.     End If
  41. End Function
May 17 '10 #7
gabrielro
4 New Member
Thanks for your reply NeoPa. I asked an ex- class-mate who know more about VB than me and he told me I could use a global function for validating the authentication, that returns a boolean result.
It looks similar with this one:
Expand|Select|Wrap|Line Numbers
  1. Function CheckLoginPass(sUsername As String, sPassword As String) As Boolean
  2. On Error GoTo ErrHandler
  3. Dim sPass As String
  4. sPass = DLookup("Password", "users", "User = '" & sUsername & "'")
  5. If sPass = sPassword Then
  6.  
  7.     CheckLoginPass = True
  8. Else
  9.     CheckLoginPass = False
  10. ErrHandler:
  11.      CheckLoginPass = False
  12. End If
  13. End Function
  14.  
And then, for validating in my case it should be something like this:
Expand|Select|Wrap|Line Numbers
  1.  If CheckLoginPass(Me.textboxuser, Me.textboxpassword) = True Then
  2.  MsgBox "Success"    
  3.  
It uses dlookup as well. Which method you guys think is more efficient, the one above or the one recommended by NeoPa?
By the way, many thanks goes to NeoPa for the encryption tip.
May 17 '10 #8
NeoPa
32,579 Recognized Expert Moderator MVP
That very much depends on what you want from it. The function is simply an encapsulation of some very similar code to do the same job.

If you feel a function interface is required then use that approach. If the code is only ever used from one position then the workings are simple enough to appear in the code without complicating it unduly. Ultimately, it's a matter of your personal choice.
May 18 '10 #9
NeoPa
32,579 Recognized Expert Moderator MVP
I've just noticed something else about the code provided by your ex-classmate. It does use a slightly different approach in that it returns the actual password into the code. Whether you use the function approach or not, I would not advise leaving that as it is if you are concerned about security. In principle, it is better that the unencrypted password is nevere used or seen except where absolutely unavoidable. Furthermore, if you had a situation where multiple passwords were allowed for the same account (used in some systems in place of multiple accounts) then this approach would have flawed logic. Not a big problem, but I'd certainly recommend the use of the technique of passing all known values to the DLookup() call to allow it to determine the validity of the data.
May 18 '10 #10

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

Similar topics

3
1247
by: Zimmermann Christian | last post by:
hello I make every week on sunday a full backup of my database(mdf =60MB / ldf = 300MB) additional i make daily from monday to saturday(6.00/12.00/18.00) three times a backup of the transaction log now I receive follow model of the backed up transactionfiles : 1.11.2004 6.00 log =130MB
16
2071
by: syncman | last post by:
In C, I would always make a log() function instead of using printfs, so that I could disable the messages or otherwise process them, all in one place. This worked in 1 line, for constant strings, but not for variable values, as in: char s; sprintf (s, "The value is %d \n", value); log (s); // 3 lines!! In C++, is it really as bad as it was? If I use streams: ostringstream oss;
4
12461
by: hype | last post by:
Hi, How can I find out how much space has been used in the log file and how much of it is free or yet to be used ? Thanks, Hype
0
1848
by: mqsash | last post by:
Hi, I have a simple C# assembly ( .dll ) which I deployed through an HTML.The complete assembly is as simple as this using System; using System.Windows.Forms; namespace testAssemblyNS { public class Class1
5
7743
by: peter Willis | last post by:
Hello, Is there a way to recover from the following error? I have (had) an existing database and wish not to lose the data tables. Thanks for any help, Pete
1
11564
by: francescomoi | last post by:
Hi. I'm experiencing some problems due to big '/var/log/mysqld.log' size (199 Mbytes), and I'd like to know if there's any method to set this file's maximum size. Thank you very much. --f
7
3913
by: Trevor Best | last post by:
According to BOL <--- BACKUP LOG Specifies a backup of the transaction log only. The log is backed up from the last successfully executed LOG backup to the current end of the log. Once the log is backed up, the space may be truncated when no longer required by replication or active transactions. ---> Does this mean I could do something else to truncate the log or is it
5
5933
by: laststubborn | last post by:
Hi All, I have a dillema that I created 2 transaction file before I started to take log back. Now I changed my recovery model from simple to full. Do I still need to keep my second transaction file? If I remove it would it be a problem for my system and log back up? If somebody responds me I really appreciate it Regards
1
1579
by: bay_dar | last post by:
It seems there has got to be a better way to work with log files where I want to keep 8 days of logs. For instance if I wanted to keep 80 days, this would be a horrible approach. How can I make this more dynamic and efficient? Const FTPOutputFile = "output-files.log" Const FTPOutputFile1 = "output-files-1.log" Const FTPOutputFile2 = "output-files-2.log" Const FTPOutputFile3 = "output-files-3.log"
7
1563
by: indiarocks | last post by:
Just a basic question, I want to create a standard log file API and want that API to be shared by all my other python files. For eg. I have file1 which creates a file handle and hands it over to say log.py Now say I have file2, and it needs to write into the same log file, how do I achieve this and what is the best way of doing it ? ------- File1: -------- log_file = file('out.log',"w") log_obj = log.log(log_file)
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.