using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace aukcijska_p
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string username = textBox1.Text;
string password = textBox2.Text;
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
MessageBox.Show("Please insert correct values.", "Incorrect Username or password.");
else
{
SqlConnection con = new SqlConnection(@"data source=(local);database=aukcija;integrated security=true;");
con.Open();
SqlCommand cmd = new SqlCommand("Select count(*) from users where name='" + username + "' and password='" + password + "'", con);
Int32 returnedCount = (Int32)cmd.ExecuteScalar();
if (returnedCount > 0)
new Window();
else
MessageBox.Show("Wrong username or password");
}
}
private void textBox1_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
}
}
<Window x:Class="aukcijska_p.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="227" Width="292">
<Grid Height="196" Width="281">
<Label Content="Username:" Height="28" HorizontalAlignment="Left" Margin="37,63,0,0" Name="label1" VerticalAlignment="Top" Width="75" />
<Label Content="Password:" Height="28" HorizontalAlignment="Left" Margin="37,99,0,0" Name="label2" VerticalAlignment="Top" Width="75" />
<Button Content="Confirm" Height="23" HorizontalAlignment="Left" Margin="157,133,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="112,68,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="112,101,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" TextChanged="textBox2_TextChanged" Visibility="Visible" />
</Grid>
</Window>
它調試normaly,但是當我按下確認,我得到消息:該程序停止working..where做我我犯了一個錯誤?任何人都可以幫助我? 香港專業教育學院做SQL數據庫與此表:用戶:USER_ID,用戶名,userPassword的,user_level
繼承人的形象: http://www39.zippyshare.com/v/97161315/file.html
嗯,它很容易受到SQL注入攻擊,一件事... – 2013-02-22 19:47:23
*不要以純文本存儲密碼* – SLaks 2013-02-22 19:47:42
重新發布您的代碼不會得到答案。請使用你的其他線程。 – Brian 2013-02-22 19:47:51