Password 5 attempts Learn programming Visual Basic (VB.net)

Lesson:

Basic Data Types


Exercise:

Password 5 attempts


Objetive:

Write a Visual Basic (VB.net) program that prompts the user for their username and password. Both should be strings. After 5 incorrect attempts, the user will be rejected.


Code:

Imports System
Public Class Exercise52
    Public Shared Sub Main()
        Dim user, pass As String
        Dim count As Integer = 0

        Do
            Console.Write("Enter username: ")
            user = Console.ReadLine()
            Console.Write("Enter password: ")
            pass = Console.ReadLine()
            count += 1
        Loop While ((user <> "user") OrElse (pass <> "password")) AndAlso (count <> 5)

        If count = 5 Then
            Console.Write("Login attemp fail!")
        Else
            Console.Write("Password correct!")
        End If
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.