Introduction:
PasswordBox is used for password entry. Generally we use it, when we want the
typed text will not display in readable form.
For working with it, we take a Silverlight
control. Then we take two TextBlock, one TextBox, one PasswordBox and one Button
by dragging it from ToolBox or by writing the following XAML code in editor
<Grid
x:Name="LayoutRoot"
Background="White">
<PasswordBox
Height="23"
HorizontalAlignment="Left"
Margin="152,87,0,0"
Name="passwordBox1"
VerticalAlignment="Top"
Width="120"
/>
<TextBox
Height="23"
HorizontalAlignment="Left"
Margin="152,41,0,0"
Name="textBox1"
VerticalAlignment="Top"
Width="120"
/>
<TextBlock
Height="23"
HorizontalAlignment="Left"
Margin="81,48,0,0"
Name="textBlock1"
Text="User
Name"
VerticalAlignment="Top"
/>
<TextBlock
Height="23"
HorizontalAlignment="Left"
Margin="81,91,0,0"
Name="textBlock2"
Text="Password"
VerticalAlignment="Top"
/>
<Button
Content="Ok"
Height="34"
HorizontalAlignment="Left"
Margin="166,150,0,0"
Name="button1"
VerticalAlignment="Top"
Width="93"
Click="button1_Click"
/>
</Grid>
We write the following code
on Button Click event
Private Sub button1_Click(sender
As System.Object,
e As System.Windows.RoutedEventArgs)
If textBox1.Text =
"user" Then
If passwordBox1.Password =
"password" Then
MessageBox.Show("Login
Succes")
Else
MessageBox.Show("Password
is not Correct")
End If
Else
MessageBox.Show("Invalid
User Name or Password")
End If
End Sub
Now, we run our application.
The output will be as like below figure

Here user is User Name
and password is Password. When we do right entry and Click ok button, then Login Success
message box is appeared as like below figure

If we do wrong entry for user
name or password, then message box is appeared with message Password
is not Correct or Invalid User Name or Password
as like below figure
