Ejemplo n.º 1
0
        public bool ValidateToken(string DBPath, string DBPwd, string encryptedtoken, ref string message)
        {
            bool Validate = true;

            try
            {
                AES objpwd = new AES();
                //DAL_LoginForm obj_DALLoginForm = new DAL_LoginForm();
                //DAL_UserMgt obj_UserMgt = new DAL_UserMgt();
                DAL_UserMgt obj_UserMgt = new DAL_UserMgt();

                Hashtable ht = new Hashtable();
                encryptedtoken = objpwd.AES_Decrypt(encryptedtoken);
                ht             = (Hashtable)JsonConvert.DeserializeObject((encryptedtoken), (typeof(Hashtable)));
                int    cid       = Convert.ToInt16(ht["cid"]);
                string username  = ht["username"].ToString();
                string password  = ht["password"].ToString();
                int    errno     = 0;
                string errstring = string.Empty;

                string    ADDomain      = string.Empty;
                bool      ADLogin       = false;
                DataTable dtUserDetails = new DataTable();
                //obj_UserMgt.GetUserDetails(ref DBPath, ref DBPwd, ref cid, ref username, ref password, ref ADDomain, ref ADLogin, ref dtUserDetails, ref _ErrNo, ref ErrString);
                //var result = obj_UserMgt.GetUserDetails(new Tuple<int, string, string, string, bool>(cid, username, password, ADDomain, ADLogin));
                obj_UserMgt.GetUserDetails(DBPath, DBPwd, cid, username, password, ADDomain, ADLogin, ref errno, ref errstring, ref dtUserDetails);
                if (dtUserDetails.Rows.Count == 0)
                {
                    Validate = false;
                    message  = "Invalid Token";
                }
            }
            catch
            {
                Validate = false;
                message  = "Invalid Token";
            }

            return(Validate);
        }
Ejemplo n.º 2
0
        public static void isEncyptionOK()
        {
            IDAL       adal = new LINQ_DAL();
            IBL        abl  = new E_Mart_BL(adal);
            Department d1   = new Department("Department 1");

            d1.DepartmentID = 1;
            User       user = new User("Naharda", "Kawabanga");
            Employee   emp  = new Employee(305, "Yair", "LAnd", 1, 50000.5, "Male", -1);
            Product    prod = new Product("Banana", "Food", 1, 1, InStock.True, 300, 2.5, 100);
            ClubMember clu  = new ClubMember("2516", "Googi", "Sheldi", "Male", "08/10/1989");

            clu.MemberID = 1;
            Receipt     rec = new Receipt();
            ProductSale ps  = new ProductSale(prod, 3);

            rec.addProductSale(ps);
            Transaction tranc = new Transaction(rec, "Cash");

            tranc.TransactionID = 1;
            E_Mart_Store e = new E_Mart_Store();

            e.addClubMember(clu);
            e.addDepartment(d1);
            e.addEmployee(emp);
            e.addProduct(prod);
            e.addTransaction(tranc);
            e.addUser(user);
            Serialize b   = new Serialize();
            AES       aes = new AES();
            String    s1  = "password";

            byte[] a        = b.SerializeObjectToByteArray(e);
            byte[] password = new byte[s1.Length * sizeof(char)];
            System.Buffer.BlockCopy(s1.ToCharArray(), 0, password, 0, password.Length);
            byte[] ans = aes.AES_Encrypt(a, password);
            Assert.IsFalse(ByteArrayCompare(a, ans));
            byte[] ans2 = aes.AES_Decrypt(ans, password);
            Assert.IsTrue(ByteArrayCompare(ans2, a));
        }