Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 pages login and signup. and I want to check whether the user is already exist or not.

What I have tried:

//this is my code in registration form


public partial class Login : System.Web.UI.Page
{
    string cs = ConfigurationManager.ConnectionStrings["NDBCS"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            LoadTrack();
        }

        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(cs);
        con.Open();
        SqlCommand cmd = new SqlCommand("Insert into tbl_User (Firstname, Lastname, Track_id, Username, Email, Password) values (@firstname, @lastname, @track, @username, @email, @password)", con);
        cmd.Parameters.AddWithValue("@firstname", txtbox_FN.Text);
        cmd.Parameters.AddWithValue("@lastname", txtbox_LN.Text);
        cmd.Parameters.AddWithValue("@track", ddl_Track.SelectedValue);
        cmd.Parameters.AddWithValue("@username", txtbox_UN.Text);
        cmd.Parameters.AddWithValue("@email", txtbox_Email.Text);
        cmd.Parameters.AddWithValue("@password", txtbox_PW.Text);
        cmd.ExecuteNonQuery();
        con.Close();
    }

    private void LoadTrack()
    {
        try
        {
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("select * from tbl_Track", con);
                con.Open();
                DataTable table = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(table);

                ddl_Track.DataSource = table;
                ddl_Track.DataValueField = "Track_id";
                ddl_Track.DataTextField = "Track_code";
                ddl_Track.DataBind();
                ddl_Track.Items.Insert(0, new ListItem("--Select Category--", "0"));
            }
        }

        catch (Exception ex)
        {

            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "Something went wrong!." + ex.Message + "";
            Label1.Visible = false;
        }
    }
Posted
Updated 29-Sep-17 1:29am
Comments
F-ES Sitecore 29-Sep-17 7:26am    
execute something like

select count(*) from tbl_User where [Username] = 'username here'

if the result isn't 0 then inform the user the account already exists.

Check the email: Either add a SQL UNIQUE Constraint[^] to the column (and use a try...catch block to handle existing users) or do a SELECT first, and see if it's there.
Me? I'd do both...

But more importantly, don't do it like that: CodeCrime: text based passwords[^]
See here: Password Storage: How to do it.[^]
 
Share this answer
 
Simple you check UserName And Email already exits or not in your Database ..
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900