Question Password Special characters

Raz

Member
Joined
Jun 7, 2010
Messages
11
Programming Experience
Beginner
Hi

I am developing a small application that need user authentication. How can I impose special character restriction. I mean how can I ask the user to enter at least 1 special character to make the password strong.

I use VB.Net 2005.

Many Thanks
 
You can try this in the textbox's Leave event. I don't know what you mean by a "special character" but the Char method will check each character in the password, and if it's either a symbol or punctuation, it will be ok.

VB.NET:
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
Dim ok As Boolean = False
Dim password As String = TextBox1.Text
Dim n As Integer = password.Length
Dim ch As Char
For x As Integer = 0 To n - 1
ch = password.Chars(x) 'same as ch = word.Substring(x, 1)
If Char.IsSymbol(ch) Or Char.IsPunctuation(ch) Then ok = True
Next x
If ok = False Then
MessageBox.Show("You must enter at least one special character")
TextBox1.Focus()
TextBox1.Clear()
Else
MessageBox.Show("OK")
End If
End Sub
 
Back
Top