Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ors_grad_.DAL
{
    class register
    {
     
        SqlConnection sqlcon;
        SqlCommand sqlcmd;
        string Output;
        public void connect()
        {
            try
            {
                sqlcon = new SqlConnection(@"Data Source=server;Initial Catalog=database;User ID=sa;Password=admin");
                sqlcon.Open();
            }
            catch (SqlException sqlerror)
            {
                foreach (SqlError e in sqlerror.Errors)
                {
                    Output = e.Message;
                }
            }
        }
        public string signUp(BLL.Register bl)
        {
            connect();
            int  uid = bl.UserId;
            string fname = bl.F_Name;
            string lname = bl.L_Name;
            string gender = bl.Gender;
            DateTime dob = bl.Dob;
            string pwd = bl.Password;
            string confirmpwd = bl.Con_Password;
            string phoneno = bl.Phone_No;
            string securityqn = bl.Security_Qn;
            string ans = bl.Ans;
            string email = bl.Email;
            string degree = bl.Degree;
            try
            {
                sqlcmd = new SqlCommand("dbo.sp_reg", sqlcon);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcon.InfoMessage += new SqlInfoMessageEventHandler(Con_InfoMessage);

                sqlcmd.Parameters.AddWithValue("@userid", uid);
                sqlcmd.Parameters.AddWithValue("@fname", fname);
                sqlcmd.Parameters.AddWithValue("@lname", lname);
                sqlcmd.Parameters.AddWithValue("@gender", gender);
                sqlcmd.Parameters.AddWithValue("@dob", dob);
                sqlcmd.Parameters.AddWithValue("@password", pwd);
                sqlcmd.Parameters.AddWithValue("@phno", phoneno);
                sqlcmd.Parameters.AddWithValue("@degree", degree);
                sqlcmd.Parameters.AddWithValue("@securityqn", securityqn);
                sqlcmd.Parameters.AddWithValue("@answer", ans);
                sqlcmd.Parameters.AddWithValue("@email", email);
                //sqlcmd.Parameters.AddWithValue("@Type", type);
                sqlcmd.ExecuteNonQuery();
            }
            catch (SqlException sqlerror)
            {
                foreach (SqlError e in sqlerror.Errors)
                {
                    Output = e.Message;
                }
            }
            return Output;
        }
        public void Con_InfoMessage(object sender, SqlInfoMessageEventArgs args)
        {
            Output = args.Message;
        }
    }
}







-------------------





C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ors_grad_.BLL
{
    class Register
    {
        private int userId;
        private string f_name;
        private string l_Name;
        private string gender;
        private DateTime dob;
        private string password;
        private string con_Password;
        private string phone_No;
        private string security_Qn;
        private string ans;
        private string email;
        private string degree;
        
        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        public string F_Name
        {
            get { return f_name; }
            set { f_name = value; }
        }
        public string L_Name
        {
            get { return l_Name; }
            set { l_Name = value; }
        }
        public string Gender
        {
            get { return gender; }
            set { gender = value; }
        }

        public DateTime Dob
        {
            get { return dob; }
            set { dob = value; }
        }
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        public string Con_Password
        {
            get { return con_Password; }
            set { con_Password = value; }
        }
        public string Phone_No
        {
            get { return phone_No; }
            set { phone_No= value; }
        }
        public string Security_Qn
        {
            get { return security_Qn; }
            set { security_Qn = value; }
        }
        public string Ans
        {
            get { return ans; }
            set { ans = value; }
        }
        public string Email
        {
            get { return email; }
            set { email = value;}
        }
        public string Degree
        {
            get { return degree; }
            set { degree = value; }
        }
        public int random()
        {
            Random rnd = new Random();
            UserId = rnd.Next(1111, 9999);
            return UserId;
            
        }
        DAL.register su = new DAL.register();
        public string signUp1()
        {
            return su.signUp(this);
        }
    }
}





--------------------------


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ors_grad_.DAL
{
    class Appstatus
    {
        SqlConnection con;
        public static string status;
        public void connect()
        {
            con = new SqlConnection(@"Data Source =server;uid=sa;password=admin;Initial Catalog =ORSgrad");
            con.Open();
        }
        public int update_status1(string appid,string status)
        {
            connect();
            status = "Processing";
            string str = "update app_status set Status='"+status+"' where AppID='" + appid + "'";
            SqlCommand cmd = new SqlCommand(str, con);
            //con.Open();
            int i = cmd.ExecuteNonQuery();
            con.Close();
            if (i == 0)
                return 1;
            else if (i == 1)
                return 2;
            return 0;
        }

        public DataSet view_all1()
        {
            //pw.tab
            connect();
            SqlCommand cmd = new SqlCommand("select * from app_status where Status='"+status+"'", con);
                        
           // con.Open();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            return ds;
            con.Close();
        }
        public SqlDataReader user_detail1()
        {
            connect();
            string str = "select distinct userid from grad_details";
            SqlDataReader dr = null;
            SqlCommand cmd = new SqlCommand(str, con);
            dr = cmd.ExecuteReader();
            return dr;
            con.Close();
        }
        public DataSet view_user_details1(string uid)
        {
            connect();
            string str = "select * from app_status where UserId='" + uid + "'";
            SqlCommand cmd = new SqlCommand(str, con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            return ds;
        }
        public SqlDataReader app_track1(string appid)
        {
            connect();
            SqlCommand cmd = new SqlCommand("Sp_TrackApp", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@appid", appid);
            SqlDataReader dr = cmd.ExecuteReader();
            //con.Close();
            return dr;
        }
    }
}




----------------------


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ors_grad_.BLL
{
    class Appstatus
    {
        DAL.Appstatus ad = new DAL.Appstatus();
        public int update_status(string appid,string status)
        {
            if (appid == "")
                return 0;
            else
                return ad.update_status1(appid,status);
        }
        public DataSet view_all()
        {
            return ad.view_all1();
        }
        public SqlDataReader user_detail()
        {
            return ad.user_detail1();
        }
        public DataSet view_user_details(string uid)
        {
                 return ad.view_user_details1(uid);
        }
        public SqlDataReader app_track(string uid)
        {
            return ad.app_track1(uid);
        }
    }
}
Posted
Updated 22-Apr-12 6:15am
v4
Comments
Shahin Khorshidnia 21-Apr-12 12:06pm    
Nice code, but what are we supposed to do?
Richard MacCutchan 21-Apr-12 14:05pm    
A great example of SQL injection vulnerability.
Nelek 22-Apr-12 12:25pm    
You updated the code but still no text, no problem description, no question... What are we supposed to do with it?

1 solution

This is a question answer forum. No one here is interested in your code.
If you want to showcase it, write a tip / trick here[^].
 
Share this answer
 
Comments
Nelek 21-Apr-12 18:10pm    
Are you sure about it? If it is vulnerable...
Abhinav S 21-Apr-12 22:43pm    
Well....it was just advice. I'm sure reviewers on the article section will mention this. SQL Injection is obviously the first threat.
VJ Reddy 23-Apr-12 19:46pm    
Good advice. 5!
Abhinav S 23-Apr-12 23:16pm    
Thank you VJ.

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