login method network in c#.net

ghorbani77

mohammad ghorbani

Posted on July 29, 2019

login method network in c#.net

login method network in c#.net

here i show how to hash password and find ip in c#.net windows forms .

private void btn\_enter\_Click(object sender, EventArgs e)        {             Automation\_systemEntities database = new Automation\_systemEntities(PublicVariable.MainConnectionString);            int addad = database.Users.Count();            MessageBox.Show(addad.ToString());            try            {                if (txt\_username.Text.Trim() != "" && txt\_password.Text.Trim() != "")                {                    /////Hash Password                    SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider();                    Byte[] B1;                    Byte[] B2;                    B1 = UTF8Encoding.UTF8.GetBytes(txt\_password.Text.Trim());                    B2 = SHA256.ComputeHash(B1);                    string HashedPassword = BitConverter.ToString(B2);                    ////////                     var Login\_query = (from U in database.Users                                       where U.UserName == txt\_username.Text.Trim()                                       where U.Password == HashedPassword                                       where U.Activity == 1                                       select U).ToList();                     if (Login\_query.Count == 1)                                       {                         ////بدست آوردن مشخصات کاربر جهت استفاده در سرتاسر برنامه                        PublicVariable.gUserFirstName = Login\_query[0].UserFirstName;                        PublicVariable.gUserFamily = Login\_query[0].UserFamily;                        PublicVariable.gUserID = Login\_query[0].UserID;                         /////ثبت اطلاعات کامپیوتر و آی پی کاربر جهت کنترل ورود و خروج                        string ComputerName = System.Environment.MachineName;                        UserLog UL = new UserLog();                        UL.ComputerName = ComputerName;                        UL.IpAddress = lbl\_IP.Text.Trim();                        UL.EnterDateTime = lbl\_date.Text + "-" +                            string.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second));                        UL.Userid = PublicVariable.gUserID;                         database.UserLogs.Add(UL);                        database.SaveChanges();                    }                    else                    {                        MessageBox.Show("کاربری با این مشخصات یافت نشد.");                        return;                    }                    //////////////////////////////////////////////////                     if (rdb\_admin.Checked)                    {                        if (Login\_query[0].UserName == "admin")                        {                            PublicVariable.gSetUser = 1; ///admin                        }                        else                        {                            MessageBox.Show("کاربری با این مشخصات یافت نشد.");                            return;                        }                    }                    else                    {                        PublicVariable.gSetUser = 2; ///users                    }                     this.Close();                 }             }            catch            {                MessageBox.Show("در ازتباط با سرور مشکلی بوجومد آمده است. لطفا مجددا تلاش کنید");                return;             }         }

The post login method network in c#.net appeared first on Mohammad Ghorbani.

💖 💪 🙅 🚩
ghorbani77
mohammad ghorbani

Posted on July 29, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related