node-mssql icon indicating copy to clipboard operation
node-mssql copied to clipboard

Parameter value only left one character when using Request Query to insert records

Open applelok opened this issue 9 years ago • 1 comments

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.

applelok avatar Oct 13 '17 07:10 applelok

I'm afraid I don't know. Somewhere like StackOverflow would probably be a better place to ask this

dhensby avatar Mar 08 '19 16:03 dhensby