sql - MySQL statement to save password to Database? -


i have sql statement saves username mysql database on phpmyadmin works charm:

dim sqlstatement string = "insert accountinfodb(`usernames`) values ('" & txtusername.text & "')" 

however

i ask users password, i'd store well, though make sense:

dim sqlstatement string = "insert accountinfodb(`usernames`, `passwords`) values ('" & txtusername.text & txtpasswd.text & "')" 

unfortunately code not work, errors valid , open connection, or syntax error in mysql syntax. wondering if knew correct way store username , password db?

here full vb.net code.

imports mysql.data.mysqlclient   public class frmsignup dim serverstring string = "server=localhost;user id=root;password=;database=accountinfo" dim sqlconnection mysqlconnection = new mysqlconnection  private sub form3_load(sender object, e eventargs) handles mybase.load     sqlconnection.connectionstring = serverstring      try         if sqlconnection.state = connectionstate.closed             sqlconnection.open()             msgbox("successfully connected db")          else             sqlconnection.close()             msgbox("failed connect db")         end if     catch ex exception         msgbox(ex.tostring)      end try end sub  public sub saveaccountinformation(byref sqlstatement string)     dim cmd mysqlcommand = new mysqlcommand      cmd         .commandtext = sqlstatement         .commandtype = commandtype.text         .connection = sqlconnection         .executenonquery()     end     sqlconnection.close()     sqlconnection.dispose() end sub  private sub btnsignup_click(sender object, e eventargs) handles btnsignup.click     if txtpasswd.text = txtpasswd2.text         messagebox.show("passwords match!")          dim sqlstatement string = "insert accountinfodb(`usernames`, `passwords`) values ('" & txtusername.text & txtpasswd.text & "')"         saveaccountinformation(sqlstatement)            messagebox.show("account registered")     else         messagebox.show("passwords not match!")         txtpasswd.text = focus()         txtpasswd.clear()         txtpasswd2.text = focus()         txtpasswd2.clear()      end if end sub end class 

edit 1

@rahul

i added sql statement code , given following error when input random username/passwd

an unhandled exception of type 'mysql.data.mysqlclient.mysqlexception' occurred in mysql.data.dll

additional information: have error in sql syntax; check manual corresponds mariadb server version right syntax use near 'test')' @ line 1

look @ sql insert statement, it's missing , comma in values section

values ('" & txtusername.text & txtpasswd.text & "')                              ^... here 

your statement should like

"insert accountinfodb(`usernames`, `passwords`)  values ('" & txtusername.text & "','" & txtpasswd.text & "')" 

edit: must mentioned current code vulnerable sql injection attack due fact passing user input directly concatenated values. should rather use sqlparameter , pass values parameter instead accordingly. sample be

dim sqlstatement string = "insert accountinfodb(`usernames`, `passwords`) values (@username, @password)"      cmd.parameters.addwithvalue("@username", txtusername.text.trim())     cmd.parameters.addwithvalue("@password", txtpasswd.text.trim()) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -