Example #1
0
        public override bool BindProperty(
            ControllerContext controllerContext,
            ModelBindingContext bindingContext,
            PropertyDescriptor propertyDescriptor)
        {
            var value =
                bindingContext.ValueProvider.GetValue($"{bindingContext.ModelName}.{propertyDescriptor.Name}") ??
                bindingContext.ValueProvider.GetValue(propertyDescriptor.Name);

            var attemptedValue = value?.AttemptedValue;

            if (attemptedValue.IsNotNullOrEmpty())
            {
                try
                {
                    var decryptedData = EncryptionTools.Decrypt(
                        attemptedValue,
                        ConfigurationManager.AppSettings["EncryptKey"]);
                    var convertor = TypeDescriptor.GetConverter(propertyDescriptor.PropertyType);
                    propertyDescriptor.SetValue(bindingContext.Model, convertor.ConvertFrom(decryptedData));
                    return(true);
                }
                catch (Exception)
                {
                    bindingContext.ModelState.AddModelError(
                        propertyDescriptor.Name,
                        $"The field '{propertyDescriptor.Name}' has an invalid value in it!");
                    return(false);
                }
            }

            propertyDescriptor.SetValue(bindingContext.Model, bindingContext.ModelType.GetDefaultValue());
            return(true);
        }
Example #2
0
        public ActionResult RegisterUser(string userName, string userEmail, string password)
        {
            var checkUser = UserDataDapper.FindUser(userName);

            if (checkUser != null)
            {
                return(Json(new { success = false, error = "用户已存在!" }));
            }
            try
            {
                string    token = Tools.GetMD5(EncryptionTools.Crypt(userName + userEmail));
                EmailInfo email = new EmailInfo();
                email.Body = $"Hi,{userName}. <br>欢迎您注册地图搜租房(woyaozufang.live),你的账号已经注册成功." +
                             "<br/>为了保证您能正常体验网站服务,请点击下面的链接完成邮箱验证以激活账号."
                             + $"<br><a href='https://woyaozufang.live/Account/Activated?activatedCode={token}'>https://woyaozufang.live/Account/Activate?activatedCode={token}</a> "
                             + "<br>如果您以上链接无法点击,您可以将以上链接复制并粘贴到浏览器地址栏打开."
                             + "<br>此信由系统自动发出,系统不接收回信,因此请勿直接回复。" +
                             "<br>如果有其他问题咨询请发邮件到[email protected].";
                email.Receiver     = userEmail;
                email.Subject      = "地图找租房-激活账号";
                email.ReceiverName = userName;
                email.Send();
                var user = new UserInfo();
                user.UserName      = userName;
                user.Password      = password;
                user.Email         = userEmail;
                user.ActivatedCode = token;
                UserDataDapper.InsertUser(user);
                return(Json(new { success = true, message = "注册成功!" }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, error = ex.ToString() }));
            }
        }
Example #3
0
 public ActionResult SendRetrievePasswordEmail(string emailAccount)
 {
     try
     {
         var       user  = UserDataDapper.FindUser(emailAccount);
         var       token = Tools.GetMD5(EncryptionTools.Crypt(user.UserName + user.Email + DateTime.Now.ToString()));
         EmailInfo email = new EmailInfo();
         email.Body = $"Hi,{user.UserName}. <br>您正在通过注册邮箱找回密码,如果非本人操作,请勿继续."
                      + "<br>请在24小时内点击以下链接重置密码:"
                      + $"<br><a href='https://woyaozufang.live/Account/ModifyPassword?token={token}'>https://woyaozufang.live/Account/ModifyPassword?token={token}</a> "
                      + "<br>如果您以上链接无法点击,您可以将以上链接复制并粘贴到浏览器地址栏打开."
                      + "<br>此信由系统自动发出,系统不接收回信,因此请勿直接回复。" +
                      "<br>如果有其他问题咨询请发邮件到[email protected].";
         email.Receiver     = user.Email;
         email.Subject      = "地图找租房-找回密码";
         email.ReceiverName = user.UserName;
         email.Send();
         UserDataDapper.SaveRetrievePasswordToken(user.ID, token);
         return(Json(new { success = true }));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, error = ex.ToString() }));
     }
 }
Example #4
0
        public void ChangeAdminDetails(string newPassword, string confirmPassword, string currentPassword)
        {
            string title = "Admin Details";

            if (newPassword != confirmPassword)
            {
                MessageBox.Show("Passwords do not match", title, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            User obj = AppDbCxt.Users.First(r => 1 == 1);

            // check if current password matches provided
            if (!obj.ConfirmPassword(currentPassword))
            {
                MessageBox.Show("Current Password Provided does not match stored password", title, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            obj.Name = UserName;
            using (MD5 md5Hash = MD5.Create())
            {
                EncryptionTools enc = new EncryptionTools(md5Hash);
                obj.Password = enc.GetMd5Hash(newPassword);
            }

            AppDbCxt.SaveChanges();
            MessageBox.Show("Details Successfully changed", title, MessageBoxButton.OK, MessageBoxImage.Information);
            CurrentPage = new ViewBooks(this);
        }
 public AccountController(UserDataDapper userDataDapper,
                          EmailService emailService,
                          EncryptionTools encryptionTools)
 {
     this.userDataDapper  = userDataDapper;
     this.emailService    = emailService;
     this.encryptionTools = encryptionTools;
 }
Example #6
0
 public bool ConfirmPassword(string testPassword)
 {
     using (MD5 md5Hash = MD5.Create())
     {
         EncryptionTools obj = new EncryptionTools(md5Hash);
         return(obj.VerifyMd5Hash(input: testPassword, hash: Password));
     }
 }
 public UserHouseController(UserDataDapper userDataDapper,
                            UserHouseDapper userHouseDapper,
                            EncryptionTools encryptionTools)
 {
     this.userDataDapper  = userDataDapper;
     this.encryptionTools = encryptionTools;
     this.userHouseDapper = userHouseDapper;
 }
Example #8
0
        private void MarkEncryptedFile()
        {
            StreamWriter writer = new StreamWriter(iniPath, false);
            string       mark   = "SYSTEM_ENCRYPTION_VALIDATOR" + keyValueSeparator + "ENCRYPTION_OK";

            mark = EncryptionTools.Encrypt(mark, encKey, true);
            writer.WriteLine(mark);
            writer.Close();
        }
Example #9
0
        public ActionResult SetEncod()
        {
            string newPwd      = EncryptionTools.MD5Encoding(password);
            string newPwd_salt = EncryptionTools.MD5Encoding(password, salt);

            ViewBag.password       = newPwd + "【----】" + newPwd_salt;
            Session["newPwd"]      = newPwd;
            Session["newPwd_salt"] = newPwd_salt;
            return(View("Login"));
        }
 public EncryptionToolsImplTests()
 {
     this.saltBuilder =
         new RandomBytesBuilderImpl(new RNGCryptoServiceProvider());
     this.hashBuilder = new SaltBasedHashBuilderImpl();
     this.tools       = new EncryptionToolsImpl(
         this.saltBuilder,
         this.hashBuilder
         );
 }
Example #11
0
        // Get the contents of the ini file.
        public bool ReadAllEntries(ref ArrayList iniEntries, ref string errorMessage)
        {
            if (!File.Exists(iniPath))
            {
                errorMessage = "Ini file not found.";
                return(false);
            }

            if (useEncryption)
            {
                if (!ValidateEncryptedIniFile())
                {
                    errorMessage = "This file is not an encrypted ini file created by this class, or decryption failed / invalid key.";
                    return(false);
                }
            }

            try
            {
                // Read the ini file into an arraylist...
                StreamReader reader   = new StreamReader(iniPath);
                string       thisLine = "";
                String[]     parts;
                iniEntries.Clear();

                //Until eof
                while (!(reader.Peek() == -1))
                {
                    thisLine = reader.ReadLine();

                    if (useEncryption)
                    {
                        thisLine = EncryptionTools.Decrypt(thisLine, encKey, true);
                        parts    = Regex.Split(thisLine, keyValueSeparator);

                        if (!(parts[0].Equals("SYSTEM_ENCRYPTION_VALIDATOR") && parts[1].Equals("ENCRYPTION_OK")))
                        {
                            iniEntries.Add(thisLine);
                        }
                    }
                    else
                    {
                        iniEntries.Add(thisLine);
                    }
                }

                reader.Close();
            }
            catch (Exception)
            {
                // The file's empty.
            }

            return(true);
        }
Example #12
0
 public WebController(UserDataDapper userDataDapper,
                      RedisService redisService,
                      QQOAuthClient qqOAuthClient,
                      UserService userService,
                      EncryptionTools encryptionTools)
 {
     _authClient      = qqOAuthClient.GetAPIOAuthClient();
     _userDataDapper  = userDataDapper;
     _userService     = userService;
     _encryptionTools = encryptionTools;
 }
Example #13
0
 public UserController(UserDataDapper userDataDapper,
                       EmailService emailService,
                       EncryptionTools encryptionTools,
                       RedisService redisService,
                       UserService userService)
 {
     this.userDataDapper  = userDataDapper;
     this.emailService    = emailService;
     this.encryptionTools = encryptionTools;
     this.redisService    = redisService;
     this.userService     = userService;
 }
 public AccountController(UserDataDapper userDataDapper,
                          EmailService emailService,
                          EncryptionTools encryptionTools,
                          UserService userService,
                          QQOAuthClient authClient)
 {
     this._userDataDapper  = userDataDapper;
     this._emailService    = emailService;
     this._encryptionTools = encryptionTools;
     this._userService     = userService;
     _authClient           = authClient.GetAPIOAuthClient();
 }
        public AccountController(UserDataDapper userDataDapper,
                                 EmailService emailService,
                                 EncryptionTools encryptionTools,
                                 IOptions <APPConfiguration> configuration
                                 )
        {
            this.userDataDapper  = userDataDapper;
            this.emailService    = emailService;
            this.encryptionTools = encryptionTools;
            this.configuration   = configuration.Value;

            this.authClient = GetOAuthClient();
        }
Example #16
0
        public static string GenerateToken(IDictionary <string, string> data, string encryptKey)
        {
            if (data.Keys.IsNullOrEmpty())
            {
                throw new ArgumentNullException("data");
            }

            var token = string.Join(
                ParameterDelimiter.ToString(),
                data.Select(item => $"{item.Key}{ValueDelimiter}{item.Value}"));
            var encryptedToken = EncryptionTools.Encrypt(token, encryptKey);

            return(HttpUtility.UrlEncode(encryptedToken));
        }
Example #17
0
 public UserController(UserDataDapper userDataDapper,
                       EmailService emailService,
                       EncryptionTools encryptionTools,
                       IOptions <APPConfiguration> configuration,
                       RedisService redisService,
                       UserService userService)
 {
     this.userDataDapper  = userDataDapper;
     this.emailService    = emailService;
     this.encryptionTools = encryptionTools;
     this.configuration   = configuration.Value;
     this.redisService    = redisService;
     this.userService     = userService;
 }
Example #18
0
        public static IHtmlString DynamicBundle(this HtmlHelper helper, params string[] files)
        {
            if (files.IsNullOrEmpty())
            {
                return(null);
            }

            var bundleName = EncryptionTools.Hash(string.Join(";", files));
            var isJs       = files.First().EndsWith(".js", StringComparison.InvariantCultureIgnoreCase);

            if (isJs)
            {
                bundleName = bundleName.StartsWith("~/") ? bundleName : $"~/Bundles/Scripts/{bundleName}";
            }
            else
            {
                bundleName = bundleName.StartsWith("~/") ? bundleName : $"~/Bundles/Styles/{bundleName}";
            }

            if (BundleTable.Bundles.All(item => item.Path != bundleName) &&
                files.IsNotNullOrEmpty())
            {
                var filePaths = files
                                .Where(file => File.Exists(helper.ViewContext.HttpContext.Server.MapPath(file)))
                                .ToArray();
                if (filePaths.IsNotNullOrEmpty())
                {
                    var newBundle = isJs
                        ? new CustomScriptBundle(bundleName) as Bundle
                        : new CustomStyleBundle(bundleName);
                    newBundle.Include(filePaths);
                    newBundle.Orderer = new SyncBundleOrder();

                    BundleTable.Bundles.Add(newBundle);
                }
            }

            var bundle = BundleTable.Bundles.SingleOrDefault(item => item.Path == bundleName);

            if (bundle == null)
            {
                return(null);
            }

            return(isJs
                ? Scripts.Render(bundle.Path)
                : Styles.Render(bundle.Path));
        }
Example #19
0
        public static Dictionary <string, string> GetTokenData(string token, string encryptKey)
        {
            token = Decode(token);
            var decryptedToken = EncryptionTools.Decrypt(token, encryptKey);

            return(decryptedToken.Split(ParameterDelimiter)
                   .Select(
                       item =>
            {
                var temp = item.Split(ValueDelimiter);
                return new KeyValuePair <string, string>(
                    temp[0],
                    temp.Length > 1 ? temp[1] : null);
            })
                   .ToDictionary(key => key.Key, val => val.Value));
        }
Example #20
0
        private void Startup(object sender, RoutedEventArgs e)
        {
            using (LibAppContext DbConn = new LibAppContext())
            {
                string password;


                using (MD5 md5Hash = MD5.Create())
                {
                    EncryptionTools obj = new EncryptionTools(md5Hash);
                    password = obj.GetMd5Hash("avertis");
                }

                int count = DbConn.Users.Count();
                if (count == 0)
                {
                    User Obj = new User(name: "admin", password: password);
                    DbConn.Users.Add(Obj);
                    DbConn.SaveChanges();
                }

                #region BorrowerTypes

                int currentTypes = DbConn.BorrowerTypes.Count();
                if (currentTypes == 0)
                {
                    //MessageBox.Show(currentTypes.ToString());
                    List <BorrowerType> defaults = new List <BorrowerType> {
                        new BorrowerType()
                        {
                            TypeName = "Student"
                        },
                        new BorrowerType()
                        {
                            TypeName = "Teacher"
                        }
                    };
                    DbConn.BorrowerTypes.AddRange(defaults);
                    DbConn.SaveChanges();
                }
                #endregion

                DbConn.Dispose();
            }
        }
Example #21
0
        public bool ValidateEncryptedIniFile()
        {
            String thisLine = "";

            String[]     parts     = null;
            StreamReader reader    = null;
            bool         validated = false;

            try
            {
                // Read the ini file into an arraylist...
                reader = new StreamReader(iniPath);

                //Until eof

                while (reader.Peek() != -1)
                {
                    thisLine = reader.ReadLine();
                    thisLine = EncryptionTools.Decrypt(thisLine, encKey, true);

                    if (thisLine.Contains(keyValueSeparator))
                    {
                        parts = Regex.Split(thisLine, keyValueSeparator);
                        if (parts[0].Equals("SYSTEM_ENCRYPTION_VALIDATOR") && parts[1].Equals("ENCRYPTION_OK"))
                        {
                            validated = true;
                            break; // TODO: might not be correct. Was : Exit While
                        }
                    }
                }

                // The file's empty.
            }
            catch (Exception) { }

            try
            {
                reader.Close();
            }
            catch (Exception) { }

            return(validated);
        }
Example #22
0
        public ActionResult CheckLogin()
        {
            #region 加密-解密
            string aaa = EncryptionTools.Md5Encrypt(password);
            EncryptionTools.Md5Decrypt(aaa);
            #endregion


            bool isFalse      = false;
            bool isFalse_salf = false;
            if (Session["newPwd"] != null)
            {
                isFalse = (Session["newPwd"].ToString() == EncryptionTools.MD5Encoding(password));
            }
            if (Session["newPwd_salt"] != null)
            {
                isFalse_salf = (Session["newPwd_salt"].ToString() == EncryptionTools.MD5Encoding(password, salt));
            }
            ViewBag.flage = isFalse + "【---】" + isFalse_salf;
            return(View("Login"));
        }
Example #23
0
        private void frmConverter_Load(object sender, EventArgs e)
        {
            Icon = Resources.kukkii;

            // Tools
            CompressionTools.LoadCompressionTools(compressionToolStripMenuItem);
            EncryptionTools.LoadEncryptionTools(encryptionToolStripMenuItem);
            HashTools.LoadHashTools(hashToolStripMenuItem);

            // Image Border Styles
            tsbImageBorderStyle.DropDownItems.AddRange(Enum.GetNames(typeof(ImageBoxBorderStyle)).Select(s => new ToolStripMenuItem {
                Image = (Image)Resources.ResourceManager.GetObject(_stylesImages[s]), Text = _stylesText[s], Tag = s
            }).ToArray());
            foreach (var tsb in tsbImageBorderStyle.DropDownItems)
            {
                ((ToolStripMenuItem)tsb).Click += tsbImageBorderStyle_Click;
            }

            UpdateForm();
            UpdatePreview();
        }
Example #24
0
        public ActionResult Login(string userName, string password)
        {
            //var loginUser = new UserInfo(){ Email="*****@*****.**", Password = "******", Status =1};
            var loginUser = UserDataDapper.FindUser(userName);

            if (loginUser != null)
            {
                if (loginUser.Status != 1)
                {
                    return(Json(new { success = false, error = "账号未激活/已被禁用,请点击激活邮件中的URL完成账号激活!" }));
                }

                if (loginUser.Password == Tools.GetMD5(password))
                {
                    var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Name, userName),
                        new Claim(ClaimTypes.Email, loginUser.Email),
                        new Claim(ClaimTypes.NameIdentifier, loginUser.ID.ToString())
                    }, CookieAuthenticationDefaults.AuthenticationScheme));
                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user,
                                            new AuthenticationProperties
                    {
                        IsPersistent = true,
                        ExpiresUtc   = DateTimeOffset.Now.Add(TimeSpan.FromDays(7)) // 有效时间
                    }).Wait();
                    string token = EncryptionTools.Crypt($"{loginUser.ID}|{loginUser.UserName}");
                    return(Json(new { success = true, token = token, messgae = "登录成功!" }));
                }
                else
                {
                    return(Json(new { success = false, error = "密码错误!" }));
                }
            }
            else
            {
                return(Json(new { success = false, error = "找不到用户信息或密码错误!" }));
            }
        }
            public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                var modelName      = bindingContext.ModelName;
                var value          = bindingContext.ValueProvider.GetValue(modelName);
                var attemptedValue = value != null ? value.AttemptedValue : null;

                if (attemptedValue.IsNotNullOrEmpty())
                {
                    try
                    {
                        var decriptedData = EncryptionTools.Decrypt(
                            attemptedValue,
                            ConfigurationManager.AppSettings["EncryptKey"]);
                        var convertor = TypeDescriptor.GetConverter(bindingContext.ModelType);
                        return(convertor.ConvertFrom(decriptedData));
                    }
                    catch
                    {
                        return(bindingContext.ModelType.GetDefaultValue());
                    }
                }

                return(ModelBinders.Binders.DefaultBinder.BindModel(controllerContext, bindingContext));
            }
Example #26
0
        public bool WriteEntry(string theKey, string theValue, ref string errorMessage)
        {
            ArrayList iniEntries = new ArrayList();
            Int32     count      = 0;
            string    tmp        = "";

            string[]      parts        = null;
            string        tmpKey       = "";
            string        tmpValue     = "";
            bool          valueWritten = false;
            StringBuilder theEntry     = new StringBuilder();

            // If ini file doesn't exist, create it.
            if (!File.Exists(iniPath))
            {
                try
                {
                    CreateFolders(GetFoldersFromPath(iniPath));
                    FileStream fs = new FileStream(iniPath, FileMode.Create);
                    fs.Close();
                }
                catch (Exception ex)
                {
                    errorMessage = "Could not create ini file: " + iniPath + ". (" + ex.Message + ")";
                    return(false);
                }
            }

            // Get the contents of the ini file, and
            // report an error reading from it, if any.
            if (!ReadAllEntries(ref iniEntries, ref tmp))
            {
                errorMessage = tmp;
                return(false);
            }

            // Delete the original ini file.
            if (!ClearINI(ref errorMessage))
            {
                return(false);
            }

            theEntry.Append(theKey);
            theEntry.Append(keyValueSeparator);
            theEntry.Append(theValue);

            try
            {
                StreamWriter writer = new StreamWriter(iniPath, useEncryption);

                if (iniEntries.Count < 1)
                {
                    tmp = theEntry.ToString();
                    if ((useEncryption))
                    {
                        tmp = EncryptionTools.Encrypt(tmp, encKey, true);
                    }

                    writer.WriteLine(tmp);
                    valueWritten = true;
                }
                else
                {
                    for (count = 0; count <= iniEntries.Count - 1; count++)
                    {
                        tmp      = Convert.ToString(iniEntries[count]);
                        parts    = Regex.Split(tmp, keyValueSeparator);
                        tmpKey   = parts[0];
                        tmpValue = parts[1];

                        // Modify ini file if the key already exists.
                        if (theKey.ToLower().Trim() == tmpKey.ToLower().Trim())
                        {
                            tmp = theEntry.ToString();
                            if ((useEncryption))
                            {
                                tmp = EncryptionTools.Encrypt(tmp, encKey, true);
                            }

                            writer.WriteLine(tmp);
                            valueWritten = true;
                        }
                        else
                        {
                            if ((useEncryption))
                            {
                                tmp = EncryptionTools.Encrypt(tmp, encKey, true);
                            }
                            writer.WriteLine(tmp);
                        }
                    }

                    // Add it to the ini file if the key didn't exist in it already
                    if (!valueWritten)
                    {
                        tmp = theEntry.ToString();
                        if ((useEncryption))
                        {
                            tmp = EncryptionTools.Encrypt(tmp, encKey, true);
                        }

                        writer.WriteLine(tmp);
                        valueWritten = true;
                    }
                }

                writer.Close();
            }
            catch (Exception ex)
            {
                errorMessage = "Error writing ini file.\n\n" + ex.Message;
                return(false);
            }

            return(valueWritten);
        }
Example #27
0
 public SigninModel(ApplicationContext context, IOptions <Constants> config)
 {
     _context    = context;
     _encryption = new EncryptionTools(config);
 }
Example #28
0
        public bool RemoveEntry(string theKey, ref string errorMessage)
        {
            ArrayList iniEntries = new ArrayList();
            Int32     count      = 0;
            string    tmp        = "";

            string[] parts        = null;
            string   tmpKey       = "";
            string   tmpValue     = "";
            bool     entryRemoved = false;

            // Get the contents of the ini file, and
            // report an error reading from it, if any.
            if (!ReadAllEntries(ref iniEntries, ref tmp))
            {
                errorMessage = tmp;
                return(false);
            }

            // Delete the original ini file.
            try
            {
                File.Delete(iniPath);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(false);
            }

            // Wait for it to be deleted...
            while (File.Exists(iniPath))
            {
                PauseWithoutBlockingUI(10);
            }

            try
            {
                StreamWriter writer = new StreamWriter(iniPath, false);

                if (iniEntries.Count < 1)
                {
                    errorMessage = "Entry does not exist.";
                    return(false);
                }
                else
                {
                    for (count = 0; count <= iniEntries.Count - 1; count++)
                    {
                        tmp      = Convert.ToString(iniEntries[count]);
                        parts    = Regex.Split(tmp, keyValueSeparator);
                        tmpKey   = parts[0];
                        tmpValue = parts[1];

                        // If we find the entry,
                        if (theKey.ToLower().Trim() == tmpKey.ToLower().Trim())
                        {
                            // Leave it out.
                            entryRemoved = true;
                        }
                        else
                        {
                            if ((useEncryption))
                            {
                                tmp = EncryptionTools.Encrypt(tmp, encKey, true);
                            }
                            writer.WriteLine(tmp);
                        }
                    }
                }

                writer.Close();
            }
            catch (Exception ex)
            {
                errorMessage = "Error writing ini file.\n\n" + ex.Message;
                return(false);
            }

            if (!entryRemoved)
            {
                errorMessage = "Entry does not exist.";
            }
            return(entryRemoved);
        }
Example #29
0
        public bool GetValue(string theKey, ref string theValue, ref string errMsg)
        {
            if (!File.Exists(iniPath))
            {
                errMsg = "Ini file not found.";
                return(false);
            }

            if (useEncryption)
            {
                if (!ValidateEncryptedIniFile())
                {
                    errMsg = "This file is not an encrypted ini file created by this class, or decryption failed / invalid key.";
                    return(false);
                }
            }

            bool valueFound = false;

            try
            {
                StreamReader reader   = new StreamReader(iniPath);
                string       thisLine = "";
                String[]     parts;

                while (!(reader.Peek() == -1)) //Until eof
                {
                    thisLine = reader.ReadLine();

                    if (useEncryption)
                    {
                        thisLine = EncryptionTools.Decrypt(thisLine, encKey, true);
                        parts    = Regex.Split(thisLine, keyValueSeparator);

                        if (!(parts[0].Equals("SYSTEM_ENCRYPTION_VALIDATOR") && parts[1].Equals("ENCRYPTION_OK")))
                        {
                            if (parts[0].Equals(theKey))
                            {
                                theValue   = parts[1];
                                valueFound = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        parts = Regex.Split(thisLine, keyValueSeparator);
                        if (parts[0].Equals(theKey))
                        {
                            theValue   = parts[1];
                            valueFound = true;
                            break;
                        }
                    }
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return(false);
            }

            if (valueFound)
            {
                return(true);
            }
            return(false);

            //ArrayList iniEntries = new ArrayList();
            //Int32 count = 0;
            //string[] parts = null;
            //string tmp = "";
            //string tmpKey = "";
            //string tmpValue = "";

            //// Get the contents of the ini file.
            //if (!ReadAllEntries(ref iniEntries, ref tmp))
            //{
            //    errMsg = tmp;
            //    return false;
            //}

            //// search for the key...
            //if (iniEntries.Count > 0)
            //{
            //    for (count = 0; count <= iniEntries.Count - 1; count++)
            //    {
            //        tmp = Convert.ToString(iniEntries[count]);
            //        parts = Regex.Split(tmp, keyValueSeparator);
            //        tmpKey = parts[0];
            //        tmpValue = parts[1];

            //        // Have we found it?
            //        if (theKey.ToLower().Trim() == tmpKey.ToLower().Trim())
            //        {
            //            theValue = tmpValue;
            //            return true;
            //        }
            //    }

            //    theValue = "";
            //}
            //else
            //{
            //    theValue = "No entries found in the ini file.";
            //}

            //return false;
        }
Example #30
0
        public string GetAccessToken(Guid applicationId, string session)
        {
            var model = AuthorizationUserInfo.Create(session, applicationId);

            return(EncryptionTools.AesEncrypt(model.ToString(), Settings.AesSecretKey));
        }