Ejemplo n.º 1
0
        /// <summary>
        /// //Method is use to Validate User Credentials from Web Server Using WEB API
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        public void ValidateUserandGetResponse(string Username, string Password)
        {
            try
            {
                UserLogin objvm = new UserLogin()
                {
                    Username = Username,
                    Password = EncryptandDecryptAES.Encrypt(Password)
                };

                ShareObject.Username = Username;
                using (var client = new WebClient())
                {
                    string ClientToken = ConfigurationManager.AppSettings["CLientIDToken"].ToString();
                    string keyValue    = ConfigurationManager.AppSettings["keyValue"].ToString();
                    string IVValue     = ConfigurationManager.AppSettings["IVValue"].ToString();


                    Uri URI = new Uri(ConfigurationManager.AppSettings["LoginURI"].ToString());
                    client.Headers.Add("Content-Type:application/json");
                    client.Headers.Add("APIKEY", GenerateToken.CreateToken(Username, ClientToken, DateTime.Now.Ticks));
                    client.Headers.Add("Accept:application/json");
                    client.UploadStringCompleted += new UploadStringCompletedEventHandler(Callback);

                    string SerializeData = JsonConvert.SerializeObject(objvm);

                    byte[] buffer = EncryptionDecryptorTripleDES.Encryption(SerializeData, keyValue, IVValue);
                    client.UploadStringAsync(URI, Convert.ToBase64String(buffer));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Users(LoginViewModel LoginViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string password = EncryptandDecryptAES.Encrypt(LoginViewModel.Password);

                    var val = LoginBL.ValidateLoginUser(LoginViewModel.Username, password);
                    if (val.RegistrationID == null)
                    {
                        Session["UserToken"] = string.Empty;
                        TempData["Message"]  = "Invalid Username and Password.";
                        return(RedirectToAction("Users", "Login"));
                    }
                    else
                    {
                        Session["UserToken"] = val.RegistrationID;
                        return(RedirectToAction("Home", "Dashboard"));
                    }
                }
                return(View("Users", LoginViewModel));
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtusername.Text == "")
                {
                    MessageBox.Show("Enter Username");
                }
                else if (txtpassword.Text == "")
                {
                    MessageBox.Show("Enter Password");
                }
                else
                {
                    string Username = txtusername.Text;
                    string Password = txtpassword.Text;

                    //Local Database check
                    var result = LoginBL.CheckUserExists(Username, EncryptandDecryptAES.Encrypt(Password));

                    if (string.IsNullOrEmpty(result) && NetConnectionChecker.Connection == false)
                    {
                        MessageBox.Show("Login Cannot be done need internet Connection");
                    }
                    else if (string.IsNullOrEmpty(result) && NetConnectionChecker.Connection == true)
                    {
                        //Method is use to Validate User Credentials from Web Server
                        ValidateUserandGetResponse(Username, Password);
                    }
                    else
                    {
                        ShareObject.CLientIDToken = result;
                        ShareObject.Username      = Username;
                        MessageBox.Show("Login Successfully");
                        this.Hide();
                        Login frm1 = new Login();
                        frm1.Close();
                        AddProduct addpro = new AddProduct();
                        addpro.Show();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public ActionResult NewUser(Registration Registration)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Registration.Password = EncryptandDecryptAES.Encrypt(Registration.Password);
             _RegistrationBL.CreateUser(Registration);
             TempData["Message"] = "Registration Done Successfully";
             return(RedirectToAction("NewUser", "Register"));
         }
         else
         {
             return(View(Registration));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }