Пример #1
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));
        }
        public HttpResponseMessage Auth(csUserMgt obj)
        {
            ResponseObject res = new ResponseObject();

            try
            {
                string  ErrString = string.Empty;
                DataSet ds        = new DataSet();

                AES objpwd = new AES();

                DAL_UserMgt obj_UserMgt   = new DAL_UserMgt();
                DataTable   dtUserDetails = new DataTable();
                int         cid           = CID; //obj.int_SiteID;
                string      username      = obj.str_UserName;
                string      ADDomain      = string.Empty;
                bool        ADLogin       = false;

                int    errno     = 0;
                string errstring = string.Empty;

                string pwd = objpwd.AES_Encrypt(obj.str_Password);
                //var result = obj_UserMgt.GetUserDetails(new Tuple<int, string, string, string, bool>(cid, username, pwd, ADDomain, ADLogin));
                obj_UserMgt.GetUserDetails(DBPath, DBPwd, cid, username, pwd, ADDomain, ADLogin, ref errno, ref errstring, ref dtUserDetails);
                //dtUserDetails = result.dsUserdetails.Tables[0];
                if (dtUserDetails != null && dtUserDetails.Rows.Count > 0)
                {
                    if (pwd == dtUserDetails.Rows[0]["Password"].ToString())
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("cid", cid);
                        ht.Add("userid", dtUserDetails.Rows[0]["UserID"].ToString());
                        ht.Add("username", username);
                        ht.Add("ledgerid", dtUserDetails.Rows[0]["LedgerID"]);
                        ht.Add("password", dtUserDetails.Rows[0]["Password"].ToString());
                        ht.Add("groupid", dtUserDetails.Rows[0]["GroupID"].ToString());
                        ht.Add("groupname", dtUserDetails.Rows[0]["GroupName"].ToString());
                        string encrypttoken = JsonConvert.SerializeObject(ht);
                        encrypttoken = objpwd.AES_Encrypt(encrypttoken);

                        DataSet dsConfigParam = new DataSet();
                        dsConfigParam = obj_UserMgt.GetConfigParam(DBPath, DBPwd, cid, Convert.ToInt32(dtUserDetails.Rows[0]["GroupID"]));
                        dsConfigParam.Tables[0].TableName = "ConfigParam";
                        dsConfigParam.Tables[1].TableName = "GroupGeneralSetting";
                        dsConfigParam.Tables[2].TableName = "BusinessPeriod";
                        int salesmanid = obj_UserMgt.GetSalesmanIDByLedgerID(DBPath, DBPwd, cid, Convert.ToInt32(dtUserDetails.Rows[0]["ledgerid"]));
                        res.respdata = new User()
                        {
                            userid = Convert.ToInt32(dtUserDetails.Rows[0]["UserID"]), username = username, ledgerid = Convert.ToInt32(dtUserDetails.Rows[0]["ledgerid"]), groupid = Convert.ToInt16(dtUserDetails.Rows[0]["GroupID"]), token = encrypttoken, configparam = dsConfigParam, salesmanid = salesmanid
                        };
                    }
                    else
                    {
                        res.errno   = 1;
                        res.errdesc = "Wrong password";
                    }
                }
                else
                {
                    res.errno   = 1;
                    res.errdesc = "Login failed";
                }
                //}
                return(Request.CreateResponse(HttpStatusCode.OK, res));
            }
            catch (Exception e)
            {
                //throw e;
                res.errno   = 1;
                res.errdesc = e.Message;
                return(Request.CreateResponse(HttpStatusCode.ExpectationFailed, res));
            }
        }