For my assignment, I was given a website which I need to make secure against SQL injection. I am attempting to do so using parameters, however I am getting an error.
The original code (below) works just fine:
function logInUser(name,pwd) {
var DBConn = getDBConnection();
var SQL = "SELECT * FROM Users WHERE UserName = '" + name + "' and UserPwd = '" + pwd + "'";
var RS = DBConn.Execute(SQL);
var valid = !RS.Eof;
if (valid) {
Session("UserID") = RS("UserID").value;
Session("UserName") = RS("UserName").value;
Session("UserFullName") = RS("UserFirstName").value + ' ' + RS("UserLastName").value;
}
DBConn.Close;
return valid;
}
I have attempted to modify it in this way: function logInUser(name,pwd) { var DBConn = getDBConnection();
var uName = name;
var uPwd = pwd;
var SQL = "SELECT * FROM Users WHERE UserName = @0 and UserPwd = @1";
var RS = DBConn.Execute(SQL,uName,uPwd);
var valid = !RS.Eof;
if (valid) {
Session("UserID") = RS("UserID").value;
Session("UserName") = RS("UserName").value;
Session("UserFullName") = RS("UserFirstName").value + ' ' + RS("UserLastName").value;
}
When I do so I get:
Provider error '80020005' Type Mismatch.
I have also tried modifying the statements to take one parameter, but then I get Engine error '80040e10' No value given for one or more required parameters.
EDITED:::
ORIGINAL::: Ok, I'll admit I don't know the database connection model you are looking for but I will bet you need to put your
uName
anduPwd
into an object:Maybe even:
possibly an array
then: