AdminLogins.cs
资源名称:yjal.rar [点击查看]
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:2k
源码类别:
Email客户端
开发平台:
Visual C++
- /********************************************************************************
- ** 作者:ebDoing
- ** 创始时间: 2008-10-22
- ** 描述:
- ** 主要用于后台管理员登陆验证,…
- ** 表:
- *********************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Configuration;
- using System.Data.SqlClient;
- namespace background
- {
- public class logins
- {
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString);
- /// <summary>
- /// 管理员登陆验证
- /// </summary>
- /// <param name="name">管理员名字</param>
- /// <param name="pass">管理员密码</param>
- /// <returns></returns>
- public bool admin(String name, String pass) {
- String T_name = name;
- String T_pass = pass;
- //使用带参数命令的可以避免SQL注入式攻击
- String sql = "select * from administrator where administrator=@administrator and password=@password";
- SqlCommand cmd = new SqlCommand(sql,conn);
- cmd.Parameters.Add("@administrator", System.Data.SqlDbType.NVarChar, 50);
- cmd.Parameters.Add("@password", System.Data.SqlDbType.NVarChar, 50);
- cmd.Parameters["@administrator"].Value = T_name;
- cmd.Parameters["@password"].Value = T_pass;
- try
- {
- conn.Open();
- SqlDataReader MyReader = cmd.ExecuteReader();
- if (MyReader.Read())
- {
- return true;
- }
- else {
- return false;
- }
- }
- catch (Exception ex)
- {
- throw (ex);
- }
- finally {
- conn.Close();
- }
- }
- }
- }