Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am a newbie in .net and need your help gurus to finalize my code. Your helpf will be much appreciated.
 
Here is the scenario:
 
A user can register using the format eg. name@ourdomain.com. Usernames are their registered name in our domain. Registration will not be accepted unless they have their names existed in our domain. During registration, username will be validated against their names existed in the domain. A list of all registered names under our domain eg. name@domain.com will be saved from our sql database.
 
Can someone help me with this please?
 
Thanks in advance for anyone who can share.
 
Eddie
Posted 24-Oct-12 23:00pm
Comments
Miguel1964 at 25-Oct-12 4:05am
   
do you want to validate, a user against your domain before saving the record to sql ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

yes.user can be accepted his/her registration after only validating entry against the one existed in our domain.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This can be achieved using an LDAP Query to your AD,
 
here is a link which will help you achieve your requirement
 
http://www.ianatkinson.net/computing/adcsharp.htm[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

thanks for your reply but i need to get deep into that. actually here is the code for logging in but i need to verify this login entry against the usernames in AD. can you share your code so i can manipulate it to fit my requirements?
 

protected void log_Click(object sender, EventArgs e)
{
SqlDataSource sds = new SqlDataSource();
sds.ConnectionString = ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ToString();
 
sds.SelectParameters.Add("username", TypeCode.String, this.username.Text);
sds.SelectParameters.Add("password", TypeCode.String, this.password.Text);
 
sds.SelectCommand = "SELECT * FROM [myTb] WHERE [username] = @username AND [password] = @password";
 
DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
try
{
if (dv.Count == 0)
{
this.lblinfo.ForeColor = System.Drawing.Color.Red;
this.lblinfo.Text = "Invalid username and password!";
return;
}
else
{
FormsAuthentication.RedirectFromLoginPage(username.Text, true);
Response.Redirect("Auth/Upload.aspx");
}
}
catch
{
 
}
finally
{

}
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

how can i use my laptop to serve as an LDAP server?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

using System.DirectoryServices;
 
    //srvr = ldap server, e.g. LDAP://yourdomain.com
    //usr = user name of the person you are trying to autenticate,
    //pwd = user password of the person you are trying to autenticate,
    public bool IsAuthenticated(string srvr, string usr, string pwd)
    {
        bool authenticated = false;
 
        try
        {
            DirectoryEntry entry = new DirectoryEntry(srvr, usr, pwd);
            object nativeObject = entry.NativeObject;
            authenticated = true;
        }
        catch (DirectoryServicesCOMException cex)
        {
            //not authenticated; reason why is in cex
        }
        catch (Exception ex)
        {
            //not authenticated due to some other exception [this is optional]
        }
        return authenticated;
    }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 25 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100