Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# login with personal databse

asp.net login

  • Please log in to reply
5 replies to this topic

#1 ravinsal

ravinsal

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 18 November 2009 - 07:32 PM

I am writing a Visual C# program for school and i need to create a login page that reads of a database, its a mdf. and i am to use a Datalinq tool with visual C# 2008. in my database is a table called Auth, with fields Name, and Psw. i neeed to authenticate and if correct direct them to Default.aspx. Its driven me crazy, i Know i can use the login tool but then i have to use the ASP.Net configuration, i need to have all the same functionality but with my Student.mdf database. I have textbox1 tacking user name and textbox2 tacking password, and a submit botton wrt now.your help is much appreciated.
Thank You :crying:
  • 0

#2 FlashM

FlashM

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 82 posts

Posted 19 November 2009 - 12:09 AM

As I can understand you want to use LINQto SQL? I haven't used it before, but I think that is really a peace of cake. I will try to check this out when I come to work and post you a replay.

For a start you can check this out: weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
  • 0

#3 ravinsal

ravinsal

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 19 November 2009 - 10:00 AM

Thanks FlashM, i have already set a linkdatasourse1 to textbox1(username), a linqdatasourse2 to textbox2(password) and a linqdatasourse3 to my submit button and connected them to the Auth table. In all of them i set the "where" so that name from table == textbox1 and so on, But i think in the class file i need to set a loop and an if else for the real authentication to work and a respond redirect at the end to go to my default,
  • 0

#4 FlashM

FlashM

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 82 posts

Posted 19 November 2009 - 10:40 AM

It's nice to hear that you've already done it. I was just going to respond but I had so much work today :-)

Anyway... Here is one cool alghorithm for encrypting passwords:



using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace Common.Tools
{
    public class CryptoTools
    {
        public static string GetSHA1hash(string str_to_hash)
        {
            byte[] bytes_to_hash = System.Text.Encoding.UTF8.GetBytes(str_to_hash);

            bytes_to_hash = g_sha1_obj.ComputeHash(bytes_to_hash);

            return Convert.ToBase64String(bytes_to_hash);
        }

        private static readonly SHA1CryptoServiceProvider g_sha1_obj = new SHA1CryptoServiceProvider();
    }
}

Before you store you PWS in database, encrypt it with this SHA-1 alghorithm. When user tries to log in, convert the value in your password textbox into SHA-1 representation and compare this with SHA-1 representation in your database.
  • 0

#5 ravinsal

ravinsal

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 19 November 2009 - 11:38 AM

Thanks for that, I am at work too, I'll try out your code when I get done, any idea on how to get the authentication working? wrt now all i have is the respond redirect in the button event handler, so when u click login(button) it directs u to the default page who ever u are , so no real authentication :confused:
  • 0

#6 FlashM

FlashM

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 82 posts

Posted 19 November 2009 - 01:30 PM

Well, I don't know much about ASP.NET but I think it should be something like this:


Profile profile = db.Profiles.Single(p => p.Username == txtUsername.Text);

if (profile != null)
{
   if (profile.Password == txtPassword.Text)
   {
       //response.redirect...
   }
   else
   {
      //Clear textboxes for new attempt...
      //Show login unsuccessful message...
   }
}

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download