私はログインフォームを作成していましたが、完了した後、私は愚かな問題を発見しました!毎回同じ値で送信されるパラメータ
私は間違ったパスワードを入力し、修正した後、再び「間違ったパスワード」を受け取った!
db.cmd.CommandText = "select count(id) from Users where [username]='"+username+"' and [password]='"+password+"'";
それ:私はすべての時間cmdが実行されることを望んで、@unと@pwは、以前の値を持って、そのため私は私のアイデアをテストするために私のコードを変更したため、それがあると思っ
string username = txt_Username.Text.Trim().ToLower();
string password = txt_Password.Text.Trim();
db.cmd.CommandText = "select count(id) from Users where [username][email protected] and [password][email protected]";
db.cmd.Parameters.AddWithValue("@un", username);
db.cmd.Parameters.AddWithValue("@pw", db._md5(password));
まだ同じ結果があります!
私はコードの魔女は今あなたが正しいパスワードを入力した後、間違ったパスワードを入力すると、正しいパスワードを入力した後、新しいフォームを開き、削除、それはあなたがパスワード)が:)
デシベルクラス正しいだと言うだろう:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Data.OleDb;
namespace My_Images
{
class Database
{
private string connection_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Jet OLEDB:Database [email protected][email protected]!;";
public OleDbConnection cn;
public OleDbCommand cmd;
public bool connection_error = false;
public string connection_error_reason;
public string _md5(string txt)
{
byte[] A = ASCIIEncoding.ASCII.GetBytes(txt);
byte[] H = MD5CryptoServiceProvider.Create().ComputeHash(A);
return BitConverter.ToString(H).Replace("-", "").ToLower();
}
public Database()
{
try
{
cn = new OleDbConnection(connection_string);
cn.Open();
connection_error = false;
}
catch(Exception e)
{
connection_error = true;
connection_error_reason = e.Message;
}
if (connection_error == false)
{
cmd = new OleDbCommand();
cmd.Connection = cn;
}
}
}
}
質問は? – C4u
答えはありませんが、 'AddWithValue'を広範囲に使用しているのであれば[そうすることの落とし穴](http://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can -we-stop-using-addwithvalue-already /)を使用します。 –
@ C4ud3xこれを修正する方法。 –