Advertisement
Guest User

Users.vb

a guest
Apr 25th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.95 KB | None | 0 0
  1. Public Class Users
  2.     Private id As Integer
  3.     Private ids As New ArrayList
  4.     Private usernames As New ArrayList
  5.     Private passwords As New ArrayList
  6.  
  7.     Public Function addUser(ByVal username As String, ByVal password As String)
  8.         If usernames.Contains(username) Then
  9.             MsgBox("A username with the name " + username + " Already exists!", MsgBoxStyle.Critical, "Error!")
  10.             Return False
  11.         End If
  12.  
  13.         If password.Length < 6 Then
  14.             MsgBox("Passowrd must be 6 characters or  longer!", MsgBoxStyle.Critical, "Error!")
  15.             Return False
  16.         End If
  17.  
  18.         If username.Length < 4 Then
  19.             MsgBox("Username must be 4 characters or  longer!", MsgBoxStyle.Critical, "Error!")
  20.             Return False
  21.         End If
  22.  
  23.         If password = username Then
  24.             MsgBox("Passowrd can't be equal to the username!", MsgBoxStyle.Critical, "Error!")
  25.             Return False
  26.         End If
  27.  
  28.         If username.Contains(" ") Then
  29.             MsgBox("Username can't contain whitespaces!", MsgBoxStyle.Critical, "Error!")
  30.             Return False
  31.         End If
  32.  
  33.         If password.Contains(" ") Then
  34.             MsgBox("Passowrd can't contain whitespaces!", MsgBoxStyle.Critical, "Error!")
  35.             Return False
  36.         End If
  37.  
  38.         ids.Add(id)
  39.         usernames.Add(username)
  40.         passwords.Add(password)
  41.         id += 1
  42.         MsgBox("The user " + username + " was registered successfully", MsgBoxStyle.OkOnly, "Success!")
  43.         Return True
  44.     End Function
  45.  
  46.     Public Function getUserFromUsername(ByVal username As String)
  47.         If Not usernames.Contains(username) Then
  48.             Return "User dosen't exist please register!"
  49.         End If
  50.         Dim user As New ArrayList
  51.         user.Add(usernames(usernames.IndexOf(username)))
  52.         user.Add(passwords(usernames.IndexOf(username)))
  53.         user.Add(ids(usernames.IndexOf(username)))
  54.  
  55.         Return user
  56.  
  57.     End Function
  58.  
  59.     Public Function getUserFromID(ByVal id As Integer)
  60.         If Not ids.Contains(id) Then
  61.             Return "User dosen't exist please register!"
  62.         End If
  63.         Dim user As New ArrayList
  64.         user.Add(usernames(id))
  65.         user.Add(passwords(id))
  66.         user.Add(ids(id))
  67.  
  68.         Return user
  69.     End Function
  70.  
  71.     Public Function Login(ByVal username As String, ByVal password As String) As Boolean
  72.         Dim user = getUserFromUsername(username)
  73.         If user Is "User dosen't exist please register!" Then
  74.             MsgBox(user, MsgBoxStyle.Critical, "Error!")
  75.             Return False
  76.         Else
  77.             If user(0) = username And user(1) = password Then
  78.                 MsgBox("Login successfull", MsgBoxStyle.OkOnly, "Success!")
  79.                 Return True
  80.             Else
  81.                 MsgBox("Password is incorrect", MsgBoxStyle.Critical, "Error!")
  82.                 Return False
  83.             End If
  84.         End If
  85.  
  86.     End Function
  87.  
  88. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement