make a userlogin as default requestor in RRS feed

  • Question

  • Hi Expert,

    Need assistance in your end, I have a user login using the code I make in login form.

    If txtBoxUsername.Text = My.Settings.AdminUser And txtBoxPassword.Text = My.Settings.AdminPass Then

    Call adminlogin()

    ElseIf txtBoxUsername.Text = My.Settings.UserUser11 And txtBoxPassword.Text = My.Settings.UserPass11 Then
    Call userlogin()


    PrivateSub Adminlogin()        Me.Hide()        Form1.Show()    EndSub

    Private Sub Userlogin()
       End Sub


    Now, I want the userlogin appear in my textbox as default my default requestor in the form. Thanks in advance



    Saturday, October 6, 2018 12:51 AM

All replies

  • Saturday, October 6, 2018 8:30 AM
  • I create module and create public function

    Public Function AdminUser() As String        AdminUser = "Administrator"

    End function

    But my problem I have several users.


    Saturday, October 6, 2018 8:32 AM
  • Using Settings is really not a fit here. One option is to use a text file, xml, json or database. plain text users can see and alter data, a database has overhead.

    With that perhaps a binary file. In the following example I write information to a binary file. One level better is to encrypt the password.

    The following class saves and loads people.

    Public Class Person
        Public Property UserName() As String
        Public Property Password() As String
        Public Property Admin() As Boolean
    End Class
    Public Class UserContainer
        Public Property FileName() As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "User.bin")
        Public Property Person() As Person
        Public Function Load() As List(Of Person)
            Dim bf As New BinaryFormatter
            Dim item As Object
            Dim person As Person
            Dim personList = New List(Of Person)
            Dim fs As New FileStream(FileName, FileMode.OpenOrCreate)
                    item = bf.Deserialize(fs)
                    If item.GetType Is GetType(Person) Then
                        person = CType(item, Person)
                    End If
                Loop While fs.Position < fs.Length - 1
                If Not (bf Is Nothing) Then
                    bf = Nothing
                End If
            End Try
            Return personList
        End Function
        Public Sub Save(pPeople As List(Of Person))
            Dim bf As New BinaryFormatter
                Using fs As New FileStream(FileName, FileMode.Create)
                    For Each person As Person In pPeople
                        bf.Serialize(fs, person)
                End Using
            Catch ex As Exception
                ' decide how to handle
                If Not (bf Is Nothing) Then
                    bf = Nothing
                End If
            End Try
        End Sub
    End Class

    Simple usaged for saving, loading, modifying.

    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Binary
    Public Class Form1
        Private People As New List(Of Person) From {
                New Person() With {.UserName = "Karen", .Password = "p1", .Admin = True},
                New Person() With {.UserName = "Bill", .Password = "p2", .Admin = False}
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ops = New UserContainer
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim ops = New UserContainer
            Dim people = ops.Load()
            For Each p As Person In people
                Console.WriteLine($"{p.UserName}, {p.Password}, {p.Admin}")
        End Sub
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim ops = New UserContainer
            Dim people = ops.Load()
            Dim person = people.FirstOrDefault(Function(p) p.UserName = "Karen")
            If person IsNot Nothing Then
                person.Password = "Temp pass"
            End If
        End Sub
    End Class
    Besides not being encrypted the caveat is, the binary file can only be works with from the one project's namespace. This can be altered too if the need arises but doubtful you need that.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, October 6, 2018 11:04 AM
  • Hi Karen,

    Hope you will can give some comments or enlightenment of creating Auto Populate a combobox Lookup Field with the Current User login credentials, this is what am asking for. 

    Saturday, October 13, 2018 1:18 AM