Guest User

Untitled

a guest
Nov 21st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using MySql.Data.MySqlClient;
  3.  
  4. namespace kadai03
  5. {
  6. public partial class _Default : System.Web.UI.Page
  7. {
  8. private bool Login(string userID, string password)
  9. {
  10. string connectInfo = string.Format("server={0};user id={1};password={2};database={3};",
  11. "localhost", "root", "", "wp22");
  12. using (var connection = new MySqlConnection(connectInfo))
  13. {
  14. connection.Open();
  15. var command = new MySqlCommand("Select Count(*) From user Where id = ?ID And pass = ?PASS;", connection);
  16. command.Parameters.AddWithValue("?ID", userID);
  17. command.Parameters.AddWithValue("?PASS", password);
  18. if (Convert.ToInt32(command.ExecuteScalar()) != 0) return true;
  19. }
  20. return false;
  21. }
  22.  
  23. protected void Page_Load(object sender, EventArgs e) { }
  24.  
  25. protected void ButtonLogin_Click(object sender, EventArgs e)
  26. {
  27. bool isCorrectUser = Login(TextBoxID.Text, TextBoxPassword.Text);
  28. if (isCorrectUser) LabelResult.Text = "ログインに成功しました。";
  29. else LabelResult.Text = "ログインに失敗しました。";
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment