1

I am relatively new to ASP.NET so I am hoping someone can help point me in the right direction.

I am creating a wedding website which will only display content if a user logs in from a login control at the top of the page.

I have a database created in SQL Server with a Table called Users that has a 6 digit int called U_ID and a 5 digit string called U_Code, and each guest to the wedding will get this ID and Code to log-in and view the website content.

I have updated my connection string in Web.Config to link to this database.

<add name="WeddingConnectionString1" connectionString="Data Source=MYPC;Initial Catalog=Wedding;Integrated Security=True" providerName="System.Data.SqlClient" />

But now I do not know how to use a login control that uses this database to allow logins.

Here is the code for my login:

 <asp:Login ID="Login1" runat="server" Orientation="Horizontal" 
  LoginButtonText="Login"    
  UserNameLabelText="ID:" RememberMeText="" TitleText="" PasswordLabelText="Code:" 
  DisplayRememberMe="False" OnAuthenticate="Login1_Authenticate">
 </asp:Login>

 <asp:ValidationSummary ID="ValidationSummary1"  
    runat="server" ForeColor="#FF0066" Height="32px" ValidationGroup="Login1"    
    Width="203px"
  />
 </login>

So I need to figure out what goes in here:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {

    }

Please help me if you can or point me somewhere that helps me do this. Thank you!

  • i wouldnt recommend the built in asp.net login controls, just use SQL query to get the logging in user's password and compare it with what the user typed in, if its the same then do your login stuff. check out Linq, it will make your sql coding much easier – Banana Jun 28 '14 at 16:42
  • 1
    Implementing a secure authentication/authorization mechanism is not a trivial task. Why dont you use the built in membership stuff? Why re-invent the wheel? – HaukurHaf Jun 28 '14 at 16:52
  • I had been hoping to use my custom database for login authentication as it is already made and also has tons of other data in it for the users. But after thinking about these two comments, I think it might be best to use the built in membership for authentication and just change some of the default settings in Identity and use Linq for other sections where I would allow users to manipulate the massive db that already exists. Thank you. – user3645143 Jun 28 '14 at 17:15
  • @HaukurHaf is absolutely right: use built-in role/membership and authentication mechanism. Rgds, – Alexander Bell Jun 28 '14 at 17:29
  • So users don't get their own individual login? So how is U_ID any different from a UserID and U_Code any different from a password? – Erik Funkenbusch Jun 28 '14 at 19:49

1 Answers1

-1

If you don't want to use readymade authentication system then you can create your own.

Just add two textboxes to the form (one having textmode as password) and a button as login.

Now in click event of button, directly use sqlcommand or your LINQ to authenticate user based on details from the textboxes.

Hope the outline helps you. Tell me if you need more information..

Anup Sharma
  • 2,053
  • 20
  • 30
  • Thank you - if I was still planning on using my previously created sql db to authenticate, this would be simple solution. – user3645143 Jul 02 '14 at 22:27