Click here to Skip to main content
15,888,070 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all

i want to create login form in mvc5.

in login function i want to check validate user.

this is my validateuser code in windows form application

how to use that windows form application validateuser code in my mvc5 application please help me

C#
SqlConnection con = new SqlConnection("Data Source=GITTWO-PC\\sql2008R2;Initial Catalog=Application;Integrated Security=SSPI");
           con.Open();
           SqlCommand cmd = new SqlCommand("validateuser", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@username", textBox1.Text);
           cmd.Parameters.AddWithValue("@password", textBox2.Text);
           cmd.Parameters.Add("@result", SqlDbType.Int).Direction = ParameterDirection.Output;
           cmd.ExecuteNonQuery();
           int result = int.Parse(cmd.Parameters["@result"].Value.ToString());
           if (result == 1)
           {
               Form2 frm = new Form2();
               frm.Show();
           }
           else if (result == 2)
           {
               //MessageBox.Show("Invalid Password", "Invalid Password");
               label3.Visible = true;
               label3.Text = "Invalid Password.......!!!";
           }
           else if (result == 3)
           {
               //MessageBox.Show("Invalid User Name", "Invalid User Name");
               label3.Text = "Invalid UserName.......!!!";
           }
           else if (result == 4)
           {
               //MessageBox.Show("Invalid User Name & Password", "Invalid User Name & Password");
               label3.Text = "Invalid UserName and Password.......!!!";

           }
           con.Close();
Posted
Updated 28-Jan-15 20:05pm
v2
Comments
krish.krish 29-Jan-15 2:07am    
this is my view page view-Indexpage

@model IEnumerable<PDMS.Model.User>

@{
//Layout = "~/Views/Shared/_UserLogin.cshtml";
Layout = null;
}


@{
ViewBag.Title = "Index";
}


<html>



<body>
<link rel="stylesheet" type="text/css" href="css/login.css" />
<div id="bodywrapper">
</div>
<div align="center" id="wrapper">
<br />
<div class="header">Personal <span>Data</span> Management <span>System </span></div>
<br />

<div class="login">
@{
Html.BeginForm("Index", "User", FormMethod.Post);
}

@Html.TextBox("txtUserName")
<br />
<br />
@Html.TextBox("txtPassword")
<br />
<br />

<input type="submit" value="Login" /> <br />
@{
Html.EndForm();
}
</div>
</div>
</body>
</html>
Deepu S Nair 29-Jan-15 2:10am    
edit your question using Improve Question Link.
krish.krish 29-Jan-15 2:23am    
i want to apply that vadidateuser function in my mvc5.

then my view page code there in above

how i will seperate that validate code in view model controller

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