我做了一个用户身份验证登录。我有3次登录。我想仅在以“accounting”登录时禁用toolstripmenu。这些是代码。 [英] I made a user authenticated login. I have 3 logins. I want to disable toolstripmenu ONLY when logged in as "accounting". These are the codes.

查看:82
本文介绍了我做了一个用户身份验证登录。我有3次登录。我想仅在以“accounting”登录时禁用toolstripmenu。这些是代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Login Form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;


namespace Trial
{ 
public partial class Form1 : Form

{

    private int _attempts;
    public static string user;



    public Form1()
    {
        InitializeComponent();
        tbuser.Text = user;
    }


    private void bexit_Click(object sender, EventArgs e)
    {
        this.Close();
        MDIParent1 mp = new MDIParent1();
        mp.Close();
    }



    public void blogin_Click(object sender, EventArgs e)
    {

        SqlConnection sc = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Marc\Documents\Trial.mdf;Integrated Security=True;Connect Timeout=30");
        SqlDataAdapter sda = new SqlDataAdapter("Select ROLE From login where username = '"+ tbuser.Text +"' and password = '"+ tbpass.Text +"'", sc);
        DataTable dt = new System.Data.DataTable();


        sda.Fill(dt);
        if (dt.Rows.Count == 1)
        {
            _attempts = 0;
            this.Hide();
            MDIParent1 mp = new MDIParent1(dt.Rows[0][0].ToString());
            mp.Show();
            // ((Form)ss).Controls["label1"].Text = dt.Rows[0][0].ToString();
        }
        else
        {
            MessageBox.Show("Invalid Username or Password");
            _attempts++;
        }
        if (_attempts == 3) this.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void lpassword_Click(object sender, EventArgs e)
    {

    }

    private void Form1_Load_1(object sender, EventArgs e)
    {

    }

    private void tbuser_TextChanged(object sender, EventArgs e)
    {

    }
}
}







MDIParent Form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Trial
{
public partial class MDIParent1 : Form
{


    public MDIParent1(string role)
    {
        InitializeComponent();
        label1.Text = role;
    }
    SqlConnection scon = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Marc\Documents\Trial.mdf;Integrated Security=True;Connect Timeout=30");

    public MDIParent1()
    {
        // TODO: Complete member initialization
    }

    private void mainWindowToolStripMenuItem_Click(object sender, EventArgs e)
    {

        mainwindow mw = new mainwindow();
        mw.MdiParent = this;
        mw.Show();


    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void MDIParent1_Load(object sender, EventArgs e)
    {


    }

    private void openToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }

    private void menuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {

    }

    private void updateEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }

    private void addEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        EMPLOYEE addemp = new EMPLOYEE();
        addemp.MdiParent = this;
        addemp.Show();

    }

    private void searchEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        EMPLOYEE2 srchemp = new EMPLOYEE2();
        srchemp.MdiParent = this;
        srchemp.Show();
    }

    private void employeeReportsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        REPORT report = new REPORT();
        report.MdiParent = this;
        report.Show();
    }

    private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SETTINGS settings = new SETTINGS();
        settings.MdiParent = this;
        settings.Show();
    }

    private void sts_Click(object sender, EventArgs e)
    {

    }

    private void toolStripStatusLabel_Click(object sender, EventArgs e)
    {

    }


}
}





我有什么试过:





What I have tried:

PLEASE HELP ME

推荐答案

绝不以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]

也见这里: Codecrime#1 [ ^ ]



然后当你已修复此问题,在成功登录时查看从数据库返回的值为ROLE,并根据您获取的值设置菜单项的Enable属性。由于我们无法访问您的数据库,因此我们不知道您存储的是哪种值,因此我们不能比那更明确......
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
See here as well: Codecrime #1[^]

Then when you've fixed that, look at the value you return from the database as "ROLE" on a successful login and set the Enable property of your menu item according to the value you get back. Since we can't access your DB we have no idea what kind of values you store there, so we can't be any more explicit than that...


这篇关于我做了一个用户身份验证登录。我有3次登录。我想仅在以“accounting”登录时禁用toolstripmenu。这些是代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆