|
-
Oct 18th, 2010, 05:35 AM
#1
Thread Starter
Junior Member
[RESOLVED] Password Validation
Hey, currently trying to figure out some basic passwork validation for a text box. The first character in the password needs to be a CAPITAL and the last character needs to be a NUMBER. This is what I have so far.
Code:
Private Sub cmdAddUser_Click()
passtest = txtPassword.Text
fPass = Mid(passtest, 1, 1)
PassLen = Len(passtest)
lPass = Mid(passtest, PassLen, 1)
IntCode = Asc(fPass)
LastCode = Asc(lPass)
If IntCode >= 65 And IntCode <= 90 Then
If LastCode >= 48 And LastCode <= 57 Then
With rs
.AddNew
!UserName = txtUser.Text
!Password = txtPassword.Text
.Update
End With
MsgBox "The new User as been successfully added to the system database"
txtUser.Text = ""
txtPassword.Text = ""
txtUser.SetFocus
Else
MsgBox "The password must contain a Capital letter as its first character, and a Number as its last character", vbCritical + vbOKOnly, "Error"
End If
End If
End Sub
Any advice would be much appreciated.
Cheers,
Damien
-
Oct 18th, 2010, 07:25 AM
#2
Re: Password Validation
I don't see any problems with the code, getting an error? Perhaps just style preference
but I would replace
fPass = Mid(passtest, 1, 1) with fPass = Left$(passtest, 1)
and
lPass = Mid(passtest, PassLen, 1) with fPass - Right$(passtest, 1)
-
Oct 18th, 2010, 08:36 AM
#3
Re: Password Validation
 Originally Posted by VBClassicRocks
lPass = Mid(passtest, PassLen, 1) with fPass - Right$(passtest, 1)
I think, you mean this:
Code:
lPass = Right$(passtest, 1)

@b0rn2fl1: Some additional suggestions:
- Trim off extra spaces
Code:
passtest = trim$(txtPassword.Text)
- And also, try to declare all variables. Otherwise, it will end in errors at some point, because VB will consider undeclared variables as Variants
..
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 18th, 2010, 12:46 PM
#4
Re: Password Validation
You need an Else clause on the first If statement. Currently you're only reporting a problem if the last character is not a Number.
Code:
If IntCode >= 65 And IntCode <= 90 Then
If LastCode >= 48 And LastCode <= 57 Then
With rs
.AddNew
!UserName = txtUser.Text
!Password = txtPassword.Text
.Update
End With
MsgBox "The new User as been successfully added to the system database"
txtUser.Text = ""
txtPassword.Text = ""
txtUser.SetFocus
Else
MsgBox "The Last character of the Password must be a Number", vbCritical + vbOKOnly, "Error"
End If
Else
MsgBox "The First character of the Password must be a Capital Letter",vbCritical + vbOKOnly,"Error"
End If
Also,and I'm sure the purists will not agree, why not say what you mean?
Rather than use Asc (most of us understand letters and numbers, not so many understand Asc)
Code:
Dim intCode As String
Dim LastCode As String
intCode = Mid$(passtest, 1, 1)
LastCode = Mid$(passtest, Len(passtest), 1)
If IntCode >= "A" And IntCode <= "Z" Then
If LastCode >= "0" And LastCode <= "9" Then
It might 'cost' some time in compilation but it might also save 'cost' when reading the code in a years time!
-
Oct 19th, 2010, 05:26 AM
#5
Thread Starter
Junior Member
Re: Password Validation
Awesome. Thanks very much for your help. Much appreciated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|