Esempio n. 1
0
 public bool ValidateUser(UserModel model)
 {
     using (_context = new karrykartEntities())
     {
         var p = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.pwd));
         return(_context.Users.Any(x => x.EmailAddress == model.user && x.Password == p));
     }
 }
Esempio n. 2
0
        public User IsAuthenticatedUser(LoginModel model)
        {
            _context      = new karrykartEntities();
            model.UserPwd = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.UserPwd));
            var user = _context.Users.Where(x => x.EmailAddress == model.UserID || x.Mobile == model.UserID).FirstOrDefault();

            _context = null;
            return((user != null) ? (user.Active.Value && user.Password == model.UserPwd) ? user : null : null);
        }
Esempio n. 3
0
        public ActionResult NewUserRegistration(FormCollection frm)
        {
            FileManager fm = new FileManager();

            string             name       = frm["txtname"].ToString();
            string             lname      = frm["lastadd"].ToString();
            string             CurntAdd   = frm["txtcadd"].ToString();
            string             Mobile     = frm["txtmob"].ToString();
            string             email      = frm["txtemail"].ToString();
            string             profession = frm["txtpro"].ToString();
            string             pass       = frm["txtpass"].ToString();
            string             ocode      = frm["txtccode"].ToString().Trim();
            string             txtcode    = frm["txtcaptcha"].ToString().Trim();
            HttpPostedFileBase file       = Request.Files["profile"];

            if (ocode == txtcode)
            {
                string mycommand = "insert into TBL_Registration values('" + name + "','" + lname + "','"
                                   + Mobile + "','" + CurntAdd + "','" + profession + "','" + email + "','" + em.EncryptData(pass) + "','"
                                   + file.FileName + "','" + DateTime.Now.ToString() + "')";
                bool x = cm.ExecuteInsertUpdateOrDelete(mycommand);
                if (x == true)
                {
                    file.SaveAs(Server.MapPath("../Content/Profile/" + file.FileName));
                    string command = "insert into TBL_Login values('" + email + "','" + em.EncryptData(pass) + "','user')";
                    if (cm.ExecuteInsertUpdateOrDelete(command))
                    {
                        Response.Write("<script>alert('Your Registration Is Completed Successfully')</script>");
                    }

                    else
                    {
                        Response.Write("<script>alert('Your Registration Is Not Completed')</script> ");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Invalid Captcha Code')</Script>");
                }
            }
            return(View());
        }
Esempio n. 4
0
        public static void Repack(string inputFolder, string outputPath, bool useCompression)
        {
            var copyPath = Path.Combine(inputFolder, Path.GetFileName(outputPath));

            RunUnityEx("import", string.Empty, copyPath);

            var decryptedData = File.ReadAllBytes(copyPath);
            var data          = EncryptionManager.EncryptData(decryptedData);

            var dir = Path.GetDirectoryName(outputPath);

            Directory.CreateDirectory(dir);

            File.WriteAllBytes(outputPath, data);
            File.WriteAllBytes($"{outputPath}.decrypt", decryptedData);
        }
        public void TestEncryption()
        {
            byte[] testData = new byte[4096];

            RandomNumberGenerator rng = RandomNumberGenerator.Create();

            rng.GetBytes(testData);

            string       checksumString = GeneralToolkitLib.Hashing.MD5.GetMD5HashAsHexString(testData);
            const string password       = "******";

            byte[] encodedbytes = EncryptionManager.EncryptData(testData, password);
            Assert.IsNotNull(encodedbytes);
            byte[] decodedBytes = EncryptionManager.DecryptData(encodedbytes, password);
            Assert.IsNotNull(decodedBytes);

            Assert.IsTrue(checksumString != GeneralToolkitLib.Hashing.MD5.GetMD5HashAsHexString(encodedbytes), "Original byte sequence cant be equal to encoded bytes!");
            Assert.IsTrue(checksumString == GeneralToolkitLib.Hashing.MD5.GetMD5HashAsHexString(decodedBytes), "Original byte sequence was not equal to decoded bytes!");
        }
Esempio n. 6
0
        public bool SetPassword(LoginModel model)
        {
            _context = new karrykartEntities();

            var user = _context.Users.Where(x => x.EmailAddress == model.UserID).FirstOrDefault();

            if (user != null)
            {
                user.Password = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.UserPwd));
                _context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
            }
            _context     = null;
            _emailHelper = new EmailHelper();

            var IsMessageSent = SendChangePasswordMessage(model.UserID);

            _emailHelper = null;
            return(IsMessageSent);
        }
Esempio n. 7
0
        public User SignUpUser(UserSignUpModel user)
        {
            _context = new karrykartEntities();
            if (!(_context.Users.Where(x => x.EmailAddress == user.user).Count() > 0))
            {
                var userToCreate = new User()
                {
                    DateCreated  = DateTime.Now,
                    EmailAddress = user.user,
                    // Mobile = CommonHelper.IsMobile(model.UserIdentifier) ? model.UserIdentifier : string.Empty,
                    Password        = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(user.pwd)),
                    UserID          = Guid.NewGuid(),
                    LastUpdated     = DateTime.Now,
                    RoleID          = CommonHelper.CustomerType.Customer,
                    Active          = false,
                    ProfileComplete = false
                };
                var userDet = new UserDetail()
                {
                    UserID    = userToCreate.UserID,
                    FirstName = user.Name.Split(' ')[0],
                    LastName  = user.Name.Split(' ').Length > 1?user.Name.Split(' ')[1]:null
                };

                var userAddress = new UserAddressDetail()
                {
                    UserID = userToCreate.UserID
                };


                _context.Users.Add(userToCreate);
                _context.UserDetails.Add(userDet);
                _context.UserAddressDetails.Add(userAddress);
                _context.SaveChanges();
                return(userToCreate);
            }

            _context = null;

            return(null);
        }
Esempio n. 8
0
 public ActionResult Changepassword(string txtold, string txtnewpass, string txtcpass)
 {
     if (txtnewpass == txtcpass)
     {
         string command = "update TBL_Login set pass='******' where email='" + Session["aid"].ToString() + "' and pass='******'";
         bool   x       = cm.ExecuteInsertUpdateOrDelete(command);
         if (x == true)
         {
             Response.Write("<script>alert('Password change successfully');window.location.herf='/Home/Login'</script>");
         }
         else
         {
             Response.Write("<script>alert('your password not changed')</script>");
         }
     }
     else
     {
         Response.Write("<script>alert('Plz confirm password')</script>");
     }
     return(View());
 }
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            var encryptedInputData = System.IO.File.ReadAllBytes(Path);
            var inputData          = EncryptionManager.DecryptData(encryptedInputData);

            byte[] outputData;

            using (var msInput = new MemoryStream(inputData))
                using (var input = new ExtendedBinaryReader(msInput, FileEncoding))
                    using (var msOutput = new MemoryStream())
                        using (var output = new ExtendedBinaryWriter(msOutput, FileEncoding))
                        {
                            while (input.Position + 2 <= input.Length)
                            {
                                var offset    = input.Position;
                                var id        = input.ReadUInt16();
                                var inputText = input.ReadString();

                                var subtitle   = subtitles.First(x => x.Offset == offset);
                                var outputText = subtitle.Translation.Replace("<Break>", "\u0001");
                                outputText = outputText.ToFullWidthChars();
                                outputText = outputText.Replace("\u0001", ",");
                                output.Write(id);
                                output.WriteString(outputText);
                            }

                            outputData = msOutput.ToArray();
                        }

            var encryptedOutputData = EncryptionManager.EncryptData(outputData);

            System.IO.File.WriteAllBytes(outputPath, encryptedOutputData);
        }
Esempio n. 10
0
        public byte[] Encode(string password)
        {
            var secureRandom       = new SecureRandomGenerator();
            var msBlock            = new MemoryStream();
            var msContent          = new MemoryStream();
            int leftPaddingLength  = secureRandom.GetRandomInt(64, 512);
            int rightPaddingLength = secureRandom.GetRandomInt(64, 512);

            byte[] sharedSecretBytes = GeneralConverters.StringToByteArray(SharedSecret);

            byte[] buffer = BitConverter.GetBytes(leftPaddingLength);
            msBlock.Write(buffer, 0, buffer.Length);

            buffer = BitConverter.GetBytes(rightPaddingLength);
            msBlock.Write(buffer, 0, buffer.Length);

            buffer = BitConverter.GetBytes(leftPaddingLength + rightPaddingLength + sharedSecretBytes.Length);
            msBlock.Write(buffer, 0, buffer.Length);

            msBlock.Write(secureRandom.GetRandomData(leftPaddingLength), 0, leftPaddingLength);
            msBlock.Write(sharedSecretBytes, 0, sharedSecretBytes.Length);
            msBlock.Write(secureRandom.GetRandomData(rightPaddingLength), 0, rightPaddingLength);

            byte[] encodeBytes = msBlock.ToArray();

            encodeBytes = EncryptionManager.EncryptData(encodeBytes, password);
            byte[] hashBytes = SHA512.Create().ComputeHash(encodeBytes, 0, encodeBytes.Length);

            buffer = BitConverter.GetBytes(encodeBytes.Length);
            msContent.Write(buffer, 0, buffer.Length);

            msBlock.WriteTo(msContent);

            buffer = BitConverter.GetBytes(hashBytes.Length);
            msContent.Write(buffer, 0, buffer.Length);
            msContent.Write(hashBytes, 0, hashBytes.Length);

            return(msContent.ToArray());
        }
Esempio n. 11
0
        public User RegisterUser(RegisterModel model)
        {
            _context = new karrykartEntities();
            if (!(_context.Users.Where(x => x.EmailAddress == model.UserIdentifier || x.Mobile == model.UserIdentifier).Count() > 0))
            {
                var user = new User()
                {
                    DateCreated     = DateTime.Now,
                    EmailAddress    = CommonHelper.IsEmail(model.UserIdentifier) ? model.UserIdentifier : string.Empty,
                    Mobile          = CommonHelper.IsMobile(model.UserIdentifier) ? model.UserIdentifier : string.Empty,
                    Password        = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.UserPwd)),
                    UserID          = Guid.NewGuid(),
                    LastUpdated     = DateTime.Now,
                    RoleID          = CommonHelper.CustomerType.Customer,
                    Active          = false,
                    ProfileComplete = false
                };
                var userDet = new UserDetail()
                {
                    UserID = user.UserID
                };

                var userAddress = new UserAddressDetail()
                {
                    UserID = user.UserID
                };


                _context.Users.Add(user);
                _context.UserDetails.Add(userDet);
                _context.UserAddressDetails.Add(userAddress);
                _context.SaveChanges();
                return(user);
            }

            _context = null;

            return(null);
        }
Esempio n. 12
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetText();

            byte[] outputData;
            var    outputMessageOffset      = new List <uint>();
            var    outputMessageExtraOffset = new List <uint>();

            using (var msOutput = new MemoryStream())
                using (var output = new ExtendedBinaryWriter(msOutput, FileEncoding))
                {
                    var outputOffset = 0u;
                    var lines        = subtitles.Translation.Split(new [] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var line in lines)
                    {
                        var pattern1 = "(?<op>\\w+)\\((?<params>.*)\\)\\;";
                        var pattern2 = "(?<op>\\w+)\\(\"(?<params>.*)\"\\)\\;";

                        var pattern = Regex.IsMatch(line, pattern2) ? pattern2 : pattern1;
                        var matches = Regex.Matches(line, pattern);
                        var opName  = matches[0].Groups["op"].Value;
                        var opParam = matches[0].Groups["params"].Value;

                        if (opName != "Text")
                        {
                            if (opName == "StartMessage")
                            {
                                outputMessageOffset.Add(outputOffset);
                                continue;
                            }

                            if (opName == "StartMessageExtra")
                            {
                                outputMessageExtraOffset.Add(uint.Parse(opParam));
                                continue;
                            }

                            var op = GameOps.FirstOrDefault(x => x.Name == opName);
                            if (op != null)
                            {
                                output.Write(op.Code);
                                var split = opParam.Split(',');
                                foreach (var s in split)
                                {
                                    if (!string.IsNullOrWhiteSpace(s))
                                    {
                                        output.Write(ushort.Parse(s.Trim()));
                                    }
                                }
                            }
                        }
                        else
                        {
                            var outputText = opParam.ToFullWidthChars();
                            foreach (var chr in outputText)
                            {
                                var c = (ushort)(chr + 128);
                                output.Write(c);
                            }
                        }

                        outputOffset = (uint)output.Position;
                    }

                    outputData = msOutput.ToArray();
                }

            byte[] unencryptedFile;
            using (var msOutput = new MemoryStream())
                using (var output = new ExtendedBinaryWriter(msOutput, FileEncoding))
                {
                    var totalMessageCount = outputMessageOffset.Count + outputMessageExtraOffset.Count;
                    output.Write((ushort)totalMessageCount);
                    output.Write((ushort)0);
                    foreach (var offset in outputMessageOffset)
                    {
                        output.Write((uint)(offset + 4 + totalMessageCount * 4));
                    }

                    foreach (var offset in outputMessageExtraOffset)
                    {
                        output.Write(offset);
                    }
                    output.Write(outputData);

                    unencryptedFile = msOutput.ToArray();
                }

            var encryptedFile = EncryptionManager.EncryptData(unencryptedFile);

            System.IO.File.WriteAllBytes(outputPath, encryptedFile);
        }
Esempio n. 13
0
        public bool ChangePassword(UserSignUpModel userModel)
        {
            using (_context = new karrykartEntities()) {
                var user = _context.Users.Where(u => u.EmailAddress == userModel.user).FirstOrDefault();

                if (user != null)
                {
                    user.Password              = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(userModel.pwd));
                    user.LastUpdated           = DateTime.Now;
                    _context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    _context.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }