2016-11-19 12 views
0

私は$ hash = password_hash($ accountpassword、PASSWORD_DEFAULT);でログインしたホームページを持っています。 (http://php.net/manual/de/function.password-hash.phpmySQl login with c#

パスワードは、$ 2y $で始まるハッシュとして保存されます。

//crypting the PW that user enter 
     string cryptedPassword = Crypter.Blowfish.Crypt(textBox_password.Text); 


     string user = textBox_username.Text; 
     string pass = cryptedPassword; 
     if (user == "" || pass == "") 
     { 
      MessageBox.Show("Empty Fields Detected ! Please fill up all the fields"); 
      return; 
     } 
     bool r = validate_login(user, pass); 
     if (r) 
      MessageBox.Show("Correct Login Credentials"); 
     else 
      MessageBox.Show("Incorrect Login Credentials"+cryptedPassword); 

私のvalidateメソッド::Crypter.Blowfish.Crypt(textBox_password.Text)で

private bool validate_login(string user, string pass) 
    { 
     db_connection(); 
     MySqlCommand cmd = new MySqlCommand(); 
     cmd.CommandText = "Select * from users where [email protected] and [email protected]"; 
     cmd.Parameters.AddWithValue("@user", user); 
     cmd.Parameters.AddWithValue("@pass", pass); 
     cmd.Connection = connect; 
     MySqlDataReader login = cmd.ExecuteReader(); 
     if (login.Read()) 
     { 
      connect.Close(); 
      return true; 
     } 
     else 
     { 
      connect.Close(); 
      return false; 
     } 
    } 

がworngある

は、私はC#でのログインを作成しました。私は$ 2aで始まるハッシュになる$

誰でもこの問題を解決するのに役立つことができますか?

答えて

1

Crypter.Blowfish.Cryptメソッドを使用するときは、2番目のパラメータのsaltを指定する必要があります。指定されていない場合はランダムなものが生成されます。明らかに、後続の呼び出しで異なるランダム値を取得しようとしています。

AlternativlyあなたはCrypterライブラリがハッシュに対して提供されたパスワードを確認するために得ることができる:

if (Crypter.CheckPassword(password, cryptedPassword)) { 
    // Valid password code here 
    return true; 
} else { 
    // Invalid password code here 
    return false; 
} 

「あなたは明らかにDBから暗号化されたパスワードを読み取る必要があるでしょうが、私はこの方法は、あなたが身を意味すると信じパスワードのハッシュのために塩を提供/保管する必要があります。

HTH

+0

hmm phpスクリプトは私の仕事ではありません。私はどのように2.パラメータを見つけることができますか? – Andreas

+0

'Crypter.Blowfish.GenerateSalt(6)'のようなものを使用して、その値を保存するか、あなたが選んだ(安全性の低い)文字列を使用してください。私はあなたの塩を保存する必要なくチェックを実行できるようにする別の方法を含めるように私の答えを更新しました。 – Graeme