String check

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

I have an app with text boxes used to change user password
Textbox1 - old password
Textbox2 - new password
Textbox3 - new password second time

What I need is how to check if the newely created password is with standart
ascii symbols. Maybe I am not describing it well, but I don't know the exact
term.

What I wont to achieve is, that the should not type password in our local
language (Bulgarian), but only in English. Because the textboxes accept
everything in Unicode I don't know how to check if textbox text is in
specific language set.

Maybe I should make a custom control, inherited from the Textbox control,
which will implement this feature, but for now I need the knowledge how to
achieve my current goal.

Any help will be greatly appreciated.
 
Nikolay,

I don't know if there is a better way, however this was where I was thinking
about

\\\
Dim ascii As System.text.Encoding = _
System.Text.Encoding.ASCII
Dim a As String = "Hello I am here"
Dim b As String = "¯??"
If a = ascii.GetString(ascii.GetBytes(a)) _
Then MessageBox.Show("I am correct")
If b <> ascii.GetString(ascii.GetBytes(b)) _
Then MessageBox.Show("I am not correct")
///

I hope this helps?

Cor
 
I've found a sample code in MSDN, which also could do the job.
It is used to dynamicaly creat SQL connection strings, but can be used in my
case also.
For anyone interested, here it is:

Private Function ValidateInput(ByVal validchars As String, _
ByVal userinput As String) As Boolean
Dim c As Char
For Each c In userinput
If validchars.IndexOf(c) < 0 Then
Return False
End If
Next
Return True
End Function

Private Sub OpenDatabase()
Dim vChars As String = _
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz*&%$#!"
Dim userid As String
Dim password As String
If ValidateInput(vChars, UserName.Text) Then
userid = UserName.Text
Else
Throw New System.Exception("Invalid user name.")
End If
If ValidateInput(vChars, PasswordText.Text) Then
password = PasswordText.Text
Else
Throw New System.Exception("Invalid password.")
End If
Dim connectionString As String
connectionString = "data source=myserver"
connectionString &= ";initial catalog=northwind"
connectionString &= ";user id=" & userid
connectionString &= ";password=" & password
SqlConnection1.ConnectionString = connectionString
SqlConnection1.Open()
' Further code to work with the database
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top