Login Form w/ Schedule, creating a form that displays a dynamic name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adawg
    New Member
    • Nov 2017
    • 2

    Login Form w/ Schedule, creating a form that displays a dynamic name

    Hi all,

    I have created a login form where both a manager and employee can login by entering their usernames and passwords. Once the employee logs in, I would like the next form (the schedule) to appear with the employees name at the top. I want the name at the top of the schedule form to be dynamic and change every time a new user logs in.

    Thanks!
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Sounds nice,

    Have you created a custom Principal for this purpose? (Here's a link to documentation for the Principal Class)

    You should be able to access the name through the Principal and display it on the screen.

    Comment

    • adawg
      New Member
      • Nov 2017
      • 2

      #3
      Thanks for the reply. All I have is a login class that has usernames and passwords for various employees. I just want the name of the person who logs in to be input into the top of the schedule form that pops up once they login. How would I use a Principal class for this?

      Comment

      • Luk3r
        Contributor
        • Jan 2014
        • 300

        #4
        This may be a silly answer, but couldn't this be accomplished with a Form_Load event OR by passing the name from your original Form? I'm not sure if it's the Form's title(text) that you're wanting to change or if it's some sort of label on the second form, but this should be fairly simple. Please note that Environment.Get EnvironmentVari able() can be substituted with a value from a textbox or inputbox. For example:

        Form Open Example:
        Code:
         Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                Form2.Text = "Form2 - " & Environment.GetEnvironmentVariable("username")
                Form2.ShowDialog()
            End Sub
        Form Load Event:
        Code:
            Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                Me.Text = "Form2 - " & Environment.GetEnvironmentVariable("username")
            End Sub

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Luk3r's suggestion sounds like it might work for your very simple case.

          I implement custom Identity and Principal classes (they implement the IIDentity and IPrincipal interfaces) and use them to authenticate the user (checking the user name and password on logging in) and to be able to enforce customized permissions based on the Roles defined in the Principal object.

          It may be overly complicated for your situation though.

          When I was in college, my first "login" project was simply to authenticate a user by checking user name and password against a database or flat text file (THIS WAS NOT SECURE). Once the user "logged in" I just stored their user name in Session (for web applications) and went from there.

          Now I do things much more securely and the custom principals make it really easy to check if the user is in roles when accessing restricted areas of my applications (whether that be web applications or desktop applications).

          While your needs may be satisfied by Luk3r's suggestion, it never hurts to be aware of Principals and Identities

          -Frinny

          Comment

          Working...