Login C#

rmokkenstorm

Freshman
Joined
Feb 20, 2006
Messages
31
I'm building a Login sript zo people can acces the data base
but need some tips or tutorials

The user has to fill in a Username, Password, And the database he/she want's to acces..
now I Thinks I should load some session of some kind..
cause there are more then one departments.. with different rights..

whit this session or some kind of..
I let them go into the next form..
this form contains a Few buttons..
But if the user is from department A he can nog see all the buttos..
Same story for department B.

should I use some kind of sessions?
where do i put this sripting (a config form or in each form or the database trigger of view)

hope you could me some good search advise of some tutorials
 
It might help if you gave some more specifics - is this a web or windows application (posting questions in the correct place helps).

What version of .Net is this being developed on? Do you currently have any existing security model or are you going to be designing everything from scratch?
 
Visual C#.net 2003.
windows forms.
There is a existing database.
The project is to build up the application in C#.net.
Almost everything exept for some view's it should be rebuild.
 
If you are developing a windows forms application then you will not need to be using session variables as these are a web concept anyway.

As a starting point you might want to investigate the GenericIdentity and GenericPrinciple classes in the framework - these will make a good starting point for a user / group based security mechanism.
 
Create a login screen. Write a simple if statment for a login method(this will use a bool). Create some way to compare username with a username in some sort of db or file and then make sure that the password is in relation to username, then return a boolean. If it makes a match, return true, otherwise return false.

Code:
boolLogin = LoginMethod( txtUsername.text, txtPassword.text);

if(boolLogin == true)
{
     //Successful login
}
else
{
    //Failed Login
}

Something like that, it is fairly simple as you can tell. If you are doing a db thats, SELECT * FROM <dbName> WHERE username = '<username>' AND password = '<password>'.

Hope this helps,

John
 
Sounds logic.
But thinks this is not correct for me.
If a user logon he/she should be a member of a group
and this will decide which buttons the user can see.
Or if the user has writting or reading rights or some table's or fields.
Or am i missing some part of do i conclude to quick.
:)
 
Sounds to be like you can use a method similar to the one that Voldron decides. If you are storing the login information in a db then you have a few choices. You could put the logins for different groups in different tables, then have the user select which group they are in when they log-on. This way the application would know which buttons to display right off the bat. Otherwise you have an extra field in the table stating the group and you would need to either set a public enum for the group in the LoginMethod method, else return a group enum (which could include an Invalid value for incorrect data).
 
what you could do is setup a switch statement that listens for a certain value, say groupNumber, so for instance groupNumber gets assigned a value the switch statment will be triggered and so on. So what I am suggesting is something like this.

Code:
int groupNumber;

switch(groupNumber)
{

   case 1:  <buttons visible for this group> break;

   ...

   default:  <default buttons to be visibile for anonymous users>       break;
}

I use this method mostly for user levels and permissions in my applications.

Cheers
 
Last edited:
Back
Top