Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub PasswordChanger(ByRef TxtBox As TextBox, ByRef PasswordInTxt As String)
- Dim CursorPosition As Integer = TxtBox.SelectionStart
- 'Changes the replacement password depending on whether a character has been added or removed
- If PasswordInTxt.Length < TxtBox.Text.Length Then
- Dim CharAdded As String = ""
- For character = 0 To TxtBox.Text.Length - 1
- If TxtBox.Text(character) <> "*" Then
- CharAdded &= TxtBox.Text(character)
- End If
- Next
- If Not (PasswordInTxt.Length + CharAdded.Length < TxtBox.Text.Length) Then
- PasswordInTxt = PasswordInTxt.Substring(0, CursorPosition - CharAdded.Count) & CharAdded & PasswordInTxt.Substring(CursorPosition - CharAdded.Count, TxtBox.Text.Length - CursorPosition)
- End If
- ElseIf PasswordInTxt.Length > TxtBox.Text.Length Then
- PasswordInTxt = PasswordInTxt.Substring(0, CursorPosition) & PasswordInTxt.Substring(CursorPosition + 1, TxtBox.Text.Length - CursorPosition)
- End If
- 'Represents the password in stars
- Dim hidden_password As String = ""
- For i = 0 To PasswordInTxt.Length - 1
- hidden_password &= "*"
- Next
- 'Sets the textbox to it's new state
- TxtBox.Text = hidden_password
- TxtBox.SelectionStart = CursorPosition
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement