Hello,
Please help me with this
public class Password
{
public static string GeneratePassword()
{
string PasswordLength = "5";
string NewPassword = "";
string allowedChars="";
allowedChars = "1,2,3,4,5,6,7,8,9,0";
allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
allowedChars += "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
allowedChars += "~,!,@,#,$,%,^,&,*,+,?";
char[] sep = { ',' };
string[] arr = allowedChars.Split(sep);
string IDString = "";
string temp = "";
Random rand = new Random();
for (int i = 0; i < Convert.ToInt32(PasswordLength); i++)
{
temp = arr[rand.Next(0, arr.Length)];
IDString += temp;
NewPassword = IDString;
}
return NewPassword;
}
public static void SavePasswordToDB()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ToString());
string strNewPassword = GeneratePassword().ToString();
SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Users(UserPassword) Values(strNewPassword)", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
I am getting the following error:
The name "strNewPassword" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
What should i pass in Values() ??
Thank you.