Advertisement
Just_Tom

Untitled

Mar 24th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.31 KB | Source Code | 0 0
  1. Private Sub PasswordChanger(ByRef TxtBox As TextBox, ByRef PasswordInTxt As String)
  2.     Dim CursorPosition As Integer = TxtBox.SelectionStart
  3.     'Changes the replacement password depending on whether a character has been added or removed
  4.    If PasswordInTxt.Length < TxtBox.Text.Length Then
  5.         Dim CharAdded As String = ""
  6.         For character = 0 To TxtBox.Text.Length - 1
  7.             If TxtBox.Text(character) <> "*" Then
  8.                 CharAdded &= TxtBox.Text(character)
  9.             End If
  10.         Next
  11.         If Not (PasswordInTxt.Length + CharAdded.Length < TxtBox.Text.Length) Then
  12.             PasswordInTxt = PasswordInTxt.Substring(0, CursorPosition - CharAdded.Count) & CharAdded & PasswordInTxt.Substring(CursorPosition - CharAdded.Count, TxtBox.Text.Length - CursorPosition)
  13.         End If
  14.     ElseIf PasswordInTxt.Length > TxtBox.Text.Length Then
  15.         PasswordInTxt = PasswordInTxt.Substring(0, CursorPosition) & PasswordInTxt.Substring(CursorPosition + 1, TxtBox.Text.Length - CursorPosition)
  16.     End If
  17.     'Represents the password in stars
  18.    Dim hidden_password As String = ""
  19.     For i = 0 To PasswordInTxt.Length - 1
  20.         hidden_password &= "*"
  21.     Next
  22.     'Sets the textbox to it's new state
  23.    TxtBox.Text = hidden_password
  24.     TxtBox.SelectionStart = CursorPosition
  25. End Sub
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement