Parameter value only left one character when using Request Query to insert records
Hi,
I am trying to insert a record by using mssql.Request:
var request = new mssql.Request();
//Using Parameters to avoid SQL Injection
request.input('officeCode', mssql.NVarChar(255), formDetail.officeCode.toUpperCase())
.input('userName', mssql.NVarChar(255), formDetail.username)
.input('pwd', mssql.NVarChar(1000), formDetail.password)
.query("insert into offices (OfficeCode, UserName, Password, UpdateTime) values " +
"(@officeCode, @userName, EncryptByPassPhrase('Encryptkey', @pwd), convert(varchar, getdate(), 120))", function (err, result) {
if (err) {
console.log(err);
deferred.reject(err);
}else{
deferred.resolve(true);
}
});
After running this code, I found the Password is only being cut and left the first character. Example: formDetail.password = Password001, in the Database I can only found "P" is stored.
Tried to change the ".input('pwd', mssql.NVarChar(1000), formDetail.password)" to ".input('pwd', mssql.NVarChar(mssql.MAX), formDetail.password)", but still no luck.
I tested to insert the @pwd to username field:
.query("insert into offices (OfficeCode, UserName, Password, UpdateTime) values " +
"(@officeCode, **@pwd**, EncryptByPassPhrase('Encryptkey', @pwd), convert(varchar, getdate(), 120))", function (err, result) {
It shows normal, the whole password is stored in username field. May I ask is it the problem of using EncryptByPassPhrase in this library? Or anything wrong in my code?
Thank you so much.
I'm afraid I don't know. Somewhere like StackOverflow would probably be a better place to ask this