• 登陆、激活、权限


    一、步骤

    1.创建数据库

    use bosamvs
    go
    create table [Login]
    (
       Username nvarchar(100),
       [Password] nvarchar(100),
       [State] bit,
       [Permissions] nvarchar(max)
    )
    insert into [Login] values('zhangsan','1234',1,'101,102,103')
    insert into [Login] values('lisi','1234',1,'101')
    insert into [Login] values('wangwu','1234',0,'101,102,103')
    select*from [Login]

    2.封装数据库

        public class Login
        {
            public string Username { get; set; }
            public string Password { get; set; }
            public bool State { get; set; }
            public string Permissions { get; set; }
        }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using 登陆_激活_权限.Model;
    using System.Data.SqlClient;
    
    namespace 登陆_激活_权限.DataOperation
    {
        public class LoginData
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            public LoginData()
            {
                conn = new SqlConnection("server=.;database=bosamvs;user=sa;pwd=123456;");
                cmd = conn.CreateCommand();
            }
    
            public Login SelectUser(string Uname, string Pwd)
            {
                Login log = null;
                cmd.CommandText = "select *from [Login] where Username=@u and Password = @p";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@u", Uname);
                cmd.Parameters.Add("@p", Pwd);
    
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    log = new Login();
                    dr.Read();
                    log.Username = dr["Username"].ToString();
                    log.Password = dr["Password"].ToString();
                    log.State = Convert.ToBoolean(dr["State"]);
                    log.Permissions = dr["Permissions"].ToString();
                }
    
                conn.Close();
                return log;
            }
    
    
        }
    }

    3.登陆、激活、权限验证

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using 登陆_激活_权限.DataOperation;
    using 登陆_激活_权限.Model;
    
    namespace 登陆_激活_权限
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //1、验证用户名
                string name = textBox1.Text;
                string pwd = textBox2.Text;
    
                Login loo = new LoginData().SelectUser(name, pwd);
                if (loo == null)
                {
                    MessageBox.Show("账户不存在!");
                }
                else
                { 
                    //1、判断账户是否激活
                    if (loo.State)
                    {
                        Form2 f2 = new Form2(this,loo);
                        f2.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("账户未激活!无法登陆!");
                    }
                }
            }
        }
    }

  • 相关阅读:
    lombok-@Accessors注解
    spring boot 当参数传入开头多个0时,报错:JSON parse error: Invalid numeric value: Leading zeroes not allowed
    linux查看历史操作记录并且显示执行时间
    IDEA中mybatis插件自动生成手写sql的xml文件
    CPU核数和load average的关系
    Jenkins--Credentials添加证书从git上拉代码
    解决输入git branch 进入编辑状态,mac下出现END,无法返回
    Git log和git reflog
    SpringCloud入门之常用的配置文件 application.yml和 bootstrap.yml区别
    springboot定时任务
  • 原文地址:https://www.cnblogs.com/bosamvs/p/5648155.html
Copyright © 2020-2023  润新知