-
Dec 27th, 2011, 06:30 AM
#1
Thread Starter
Member
Password which consists capital letter, number, small letter
Hi,
I want to have a password which consists capital letters, small letters, numbers and special characters. How can I make it?
Thanks for replying
-
Dec 27th, 2011, 07:19 AM
#2
Re: Password which consists capital letter, number, small letter
On the assumption it has to be 8 characters or more in length and must have at least: one Capital Letter, one Lower Case Letter, one Nmber and one Special Character:
Code:
Private Sub cmdChekPWD_Click()
Dim bytFlag As Byte
Dim intI As Integer
Dim strC As String
If Len(txtPassword.Text) >= 8 Then
For intI = 1 To Len(txtPassword.Text)
strC = Mid$(txtPassword.Text, intI, 1)
If strC >= "!" And strC <= "\" Then
bytFlag = bytFlag Or &H8
End If
If strC >= "0" And strC <= "9" Then
bytFlag = bytFlag Or &H4
End If
If strC >= ":" And strC <= "@" Then
bytFlag = bytFlag Or &H8
End If
If strC >= "A" And strC <= "Z" Then
bytFlag = bytFlag Or &H2
End If
If strC >= "a" And strC <= "z" Then
bytFlag = bytFlag Or &H1
End If
Next intI
End If
If bytFlag <> &HF Then
MsgBox "Invalid Password"
End If
End Sub
-
Dec 27th, 2011, 07:35 AM
#3
Re: Password which consists capital letter, number, small letter
"must have at least: one Capital Letter, one Lower Case Letter, one Number and one Special Character"
Unless I misunderstand the requirements it looks like Axxxxx111 passes the test but does not have any special characters.
-
Dec 27th, 2011, 08:18 AM
#4
Re: Password which consists capital letter, number, small letter
Try this:
Code:
Option Explicit
Private Sub Command1_Click()
If Not CheckPassword("abcdefg123") Then
MsgBox "Invalid password - it must contain at least 1 capital letter, 1 lower and 1 numeric character.", _
vbExclamation, "Invalid Password"
Exit Sub
Else
'proceeed with normal processing...
Debug.Print "password is ok..."
End If
End Sub
Private Function CheckPassword(sPwd As String) As Boolean
Dim i As Integer
Dim bCapital As Boolean
Dim bLower As Boolean
Dim bNumberic As Boolean
Dim iAscii As Integer
For i = 1 To Len(sPwd)
iAscii = Asc(VBA.Mid$(sPwd, i, 1))
If Not bCapital Then
bCapital = CBool(iAscii >= 65 And iAscii <= 90)
End If
If Not bLower Then
bLower = CBool(iAscii >= 97 And iAscii <= 122)
End If
bNumberic = IsNumeric(VBA.Mid$(sPwd, i, 1))
If bCapital And bLower And bNumberic Then Exit For
Next i
CheckPassword = (bCapital And bLower And bNumberic)
End Function
Last edited by RhinoBull; Dec 27th, 2011 at 08:24 AM.
-
Dec 27th, 2011, 09:11 AM
#5
Re: Password which consists capital letter, number, small letter
Regular expression can be used here also.
Code:
Private Function ValidatePassword(ByVal sPass) As Boolean
Dim regEx
Set regEx = CreateObject("vbscript.regexp")
'At least 8 characters
'At least 1 number
'At least 1 lowercase letter
'At least 1 uppercase letter
'At least 1 special character. Special charaters include !@#$%^&+=
regEx.Pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$"
ValidatePassword = regEx.Test(sPass)
Set regEx = Nothing
End Function
-
Dec 27th, 2011, 09:18 AM
#6
Frenzied Member
Re: Password which consists capital letter, number, small letter
do you want to make one ( function generator(byval size as integer, byval specials as string)as string)?
or just test one (function Test(by val pwd as string) as bool )?
the use of special characters can be a problem for systems so..
can you provide an allowable set for the system/user to use?
oh yes its not just the girls who think size matters... so...
how many digits?
here to talk
-
Dec 27th, 2011, 09:22 AM
#7
Frenzied Member
Re: Password which consists capital letter, number, small letter
nice one MarkT
I was going to do something similar
but can you explain the regular expression expression for the benefit of the forum
its a little too esoteric for some of them
here to talk
-
Dec 27th, 2011, 10:32 AM
#8
Thread Starter
Member
Re: Password which consists capital letter, number, small letter
Firstly, thanks for replies..
Actually I wanted the user has to determine a password which consists at least; one capital letter, one small letter, one number and one special character as you said..
Doogle, it works.. Could you explain its idea?
RhinoBull, it always says "Invalid password - it must contain at least 1 capital letter, 1 lower and 1 numeric character."
MarkT, I didn't understand what you meant..
-
Dec 27th, 2011, 10:44 AM
#9
Re: Password which consists capital letter, number, small letter
Originally Posted by _MeRKeZ_
RhinoBull, it always says "Invalid password - it must contain at least 1 capital letter, 1 lower and 1 numeric character."..
That's because I used "abcdefg123" as a test password - change it to whatever (perhaps to "Abcdefg123") to see how it works.
Also, substitute hadcoded string with perhaps txtPassword.Text to make it dynamic.
-
Dec 27th, 2011, 10:47 AM
#10
Re: Password which consists capital letter, number, small letter
"Doogle, it works.. Could you explain its idea?"
Did you try Axxxxx111
-
Dec 27th, 2011, 10:47 AM
#11
Re: Password which consists capital letter, number, small letter
Originally Posted by _MeRKeZ_
MarkT, I didn't understand what you meant..
What didn't you understand? The usage would be
Code:
Private Function ValidatePassword(ByVal sPass) As Boolean
Dim regEx
Set regEx = CreateObject("vbscript.regexp")
'At least 8 characters
'At least 1 number
'At least 1 lowercase letter
'At least 1 uppercase letter
'At least 1 special character. Special charaters include !@#$%^&+=
regEx.Pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$"
ValidatePassword = regEx.Test(sPass)
Set regEx = Nothing
End Function
Private Sub Command1_Click()
MsgBox "Valid = " & ValidatePassword(Text1.Text)
End Sub
-
Dec 27th, 2011, 11:42 AM
#12
Re: Password which consists capital letter, number, small letter
Originally Posted by TysonLPrice
it looks like Axxxxx111 passes the test but does not have any special characters.
Yup, there's an error in my code.
Code:
If strC >= "!" And strC <= "\" Then
should be
Code:
If strC >= "!" And strC <= "/" Then
Apart from that, I think it solves OP's original problem (although it's probably not the best solution)
BTW It works by checking each character in txtPassword, if it's a 'special character' between '!' and '/' it sets Bit 3 of bytFlag, if it's between '0' and '9' it sets Bit 2 of bytFlag, if it's between ':' and '@' it sets Bit 3 of bytFlag, if it's between 'A' and 'Z' it sets Bit 1 of bytFlag, if it's between 'a' and 'z' it sets bit 0 of bytFlag.
So after all the characters have been examined, if there was at least one of each (Capital, Lower Case, Number, Special Character) bytFlag will equal &h0F.
(Bit0 = 1, Bit1 = 2, Bit2 = 4, Bit3 = 8, add them all up and it's 15 = &hF)
Last edited by Doogle; Dec 27th, 2011 at 12:42 PM.
-
Dec 27th, 2011, 11:50 AM
#13
Frenzied Member
Re: Password which consists capital letter, number, small letter
thats what I like to see most of you telling what it does and not just telling what it is
If this continues the newbies might learn a thing or two
long may it continue...
but what does, for the benefit of the op and other forum users
the
Code:
regEx.Pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$"
mean
the structure and how to read it would help everyone to get theri heads around regex
for many it is more than alien territory
here to ... (well i am just here)
-
Dec 27th, 2011, 11:54 AM
#14
Re: Password which consists capital letter, number, small letter
Originally Posted by incidentals
thats what I like to see most of you telling what it does and not just telling what it is
If this continues the newbies might learn a thing or two
long may it continue...
but what does, for the benefit of the op and other forum users
the
Code:
regEx.Pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$"
mean
the structure and how to read it would help everyone to get theri heads around regex
for many it is more than alien territory
here to ... (well i am just here)
Regular expressions aren't something, at least to me, you can just easily explain. You need to know what kind of animal it is and the basic concepts. Look here:
http://www.regular-expressions.info/
-
Dec 27th, 2011, 12:10 PM
#15
Re: Password which consists capital letter, number, small letter
Yea, what TysonLPrice said.
Here is another link that will probably confuse you more as to what the expression is doing. http://www.regular-expressions.info/reference.html
Basically you can break it apart for each of the checks you need
The check for least at 8 characters
The check for at least 1 number
The check for at least 1 lowercase letter
The check for at least 1 uppercase letter
The check for at least 1 special character. Special charaters include !@#$%^&+=
^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$
To be honest most of the time if I need a complex expression I will just google for it.
-
Dec 27th, 2011, 12:39 PM
#16
Frenzied Member
Re: Password which consists capital letter, number, small letter
the reference to the regex expression is a good idea
its the sheer alien-ness of them that I think the newbies will find hard if not horrifying
its all well and good to say "rolled up bits of newspaper 1 inch wide will stop the elephants from coming"
and to be "proved right" because they havent arrived yet!
its another to understand why the process works and how to use it fruitfully in the future against the rhinos
its the how and why they need ( newbies )
the answers alone are not going to broaden their understanding
there I go ranting again... I'd better off and check my sugars
here to talk
Last edited by incidentals; Dec 27th, 2011 at 12:46 PM.
-
Dec 28th, 2011, 11:31 AM
#17
Thread Starter
Member
Re: Password which consists capital letter, number, small letter
Thanks for your replies, I think it's gonna work anymore
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|