Yorick85542165

I have a login in form at the moment that simply checks the inputted username and password with the sql database table to see if they are correct and if so opens another form. Now I want to create an account that tracks the user who has logged in so as to display information only relevant to them from their table as well as saving there actions to the table.

Is this possible and if so is there a general approach I should take


Re: Visual C# Express Edition How to implement User Accounts for a windows application.

Figo Fei - MSFT

Hi,

You can do it in this way.

But I should remind you to keep your connection string and other sensitive code in your program secure. ( please check the SqlConnectionStringBuilder.Encrypt .)

Otherwise, you can use encrypted file to save the user and password information. But it is another story.

Thanks






Re: Visual C# Express Edition How to implement User Accounts for a windows application.

Yorick85

Hey Thanks,

So its possible then. I just don't know where to start with keeping the value of the logged in user for the application. How would I keep this information for the period the user is logged in because at the moment it just forgets and opens up a new form upon login.




Re: Visual C# Express Edition How to implement User Accounts for a windows application.

Figo Fei - MSFT

Hello, Yorick

You can save the information (user name and password in the database) as you mentioned in the first post.

When a user run the application, the scenario is:

to access the database to check the data( username and password ) and then give more action.

1: create a table in database to store user name and password (I recommend encrypting the password in the table)

2: make connection to database

3: take SQL query statement to search in the database using the text in User name textboxs as parameter username.(SELECT Password FROM TableName WHERE Users=@username)

4: compare the password returned and the text in the Password textboxs (you may use dataReader, see: http://msdn2.microsoft.com/en-us/library/haa3afyz.aspx)

In this way, you can complete your login form in the application.

For more information, see http://msdn2.microsoft.com/en-us/library/wzabh8c4(VS.80).aspx

Otherwise, you can use encrypted file or somthing else to store the information, but it is another story.

Thanks






Re: Visual C# Express Edition How to implement User Accounts for a windows application.

Yorick85

Hey thanks,

I have managed to get this working but I wanted to keep track that this user has logged in and only display information

relevant to the user because at the moment the user logs in and it is forgotten who has logged in.





Re: Visual C# Express Edition How to implement User Accounts for a windows application.

Figo Fei - MSFT

Hi,

So you could keep the identifying infomation in the memory (instead of "verify once and lose forever") during the whole application life time to keep track of who is the current user. Do verifying where you need.

For example, when a user login then you record his user name in a general variable of application scope. Then detect the user name recorded. Just something like session mechanism in ASP.NET

Thanks