Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am creating simple login page using ajax,jquery and webmethod first time login not successfully . break point call every time and sql query executed successfully but success alert not come in some time. some time execute successfully. and not login other system when use in iis lease help me any one . thanks in advance.if once login successfully not come that issue in particular time

What I have tried:

JavaScript
<script type="text/javascript">
    function login_tracking(username,password)
    {
    var obj = {};
        obj.username = username;
        obj.password= password;
            $.ajax({
            url: "Tracking.aspx/login",
            data: JSON.stringify(obj),
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: function(data) { 
            alert("sucess");
            var d=data.d.length;
            if(d==0)
            {
            alert("Login Failed");
            }
            alert(data.d[0].username + "  Login Sucessfully");
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Login Error');
            }
        });
    
    }
     </script>


C#
public static List<loginclass> login(string username, string password)
   {
       MasterLogic objMas = new MasterLogic();
       List<loginclass> login = new List<loginclass>();
       string qry = " select a.CompanyCode,CompanyName,UserName from webuser_master a,company_master b " +
                    " where a.CompanyCode=b.CompanyCode and a.UserId ='" + username + "' and " +
                    " a.UserPWD='" + password + "' and a.Status='1' group by b.CompanyName ";
       DataTable dt = objMas.GetDataTable(qry);
       if (dt == null)
           return login;
       DataSet ds = new DataSet();
       ds.Tables.Add(dt);
       string code, uname,cname;
       List<datarow> list = dt.AsEnumerable().ToList();
       foreach (DataRow dr in dt.Rows)
       {
           code = dr["CompanyCode"].ToString();
           uname = dr["UserName"].ToString();
           cname = dr["CompanyName"].ToString();
           login.Add(new loginclass(code,uname,cname));
       }

       return login;


   }
Posted
Updated 29-Aug-16 3:56am
v2

1 solution

There are so many wrong things going on here...let's just hit the highlights with the top two "most dangerous things to do when logging in users" list:

1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. And concatenating strings at login not only hands your DB to everyone, it lest them bypass your security completely and login in as you or any other user without even knowing your password...

2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
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