コード例 #1
0
        public void Encrypt(IUser user)
        {
            if (IsEncrypt)
            {
                return;
            }

            if (!IsDownloaded)
            {
                throw new ArgumentException("An undownloaded message cannot encrypt");
            }

            if (!user.IsAuthorized)
            {
                throw new ArgumentException("User is unauthorized, message cannot encrypt");
            }

            ISecureManager secureManager = ModulesManager.GetModulesManager().GetSecureManager();

            string password = secureManager.DecryptWithAes(user.EncryptedPassword);

            if (type != StashMessageType.Empty)
            {
                content = secureManager.EncryptWithAesHmac(content, password);
            }

            IsEncrypt = true;
        }
コード例 #2
0
        public void CreateUser(long chatId, string password)
        {
            ISecureManager secureManager = ModulesManager.GetSecureManager();

            if (IsUserExist(chatId))
            {
                LogoutUser(chatId);

                using (UsersContext db = new UsersContext())
                {
                    UserModel userModel = db.Users
                                          .Where(user => user.ChatId == chatId)
                                          .First();

                    userModel.HashPassword = secureManager.CalculateHash(password);
                    db.SaveChanges();
                }
            }
            else
            {
                using (UsersContext db = new UsersContext())
                {
                    UserModel userModel = new UserModel
                    {
                        ChatId       = chatId,
                        HashPassword = secureManager.CalculateHash(password)
                    };

                    db.Users.Add(userModel);
                    db.SaveChanges();
                }
            }
        }
コード例 #3
0
        internal static ISecureManager GetSecureManager()
        {
            if (secureManager == null)
            {
                secureManager = new SecureManager();
            }

            return(secureManager);
        }
コード例 #4
0
 private ModulesManager()
 {
     telegramBotClient = new TelegramBotClient(BotToken.Get());
     messageManager    = new MessageManager();
     sessionManager    = new SessionManager();
     userManager       = new UserManager();
     secureManager     = new SecureManager();
     databaseManager   = new DatabaseManager();
 }
コード例 #5
0
ファイル: UserLocal.cs プロジェクト: dmitrydnl/StashBot
        public void Login(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Password cannot be null");
            }

            ISecureManager secureManager = ModulesManager.GetSecureManager();

            EncryptedPassword = secureManager.EncryptWithAes(password);
            IsAuthorized      = true;
        }
コード例 #6
0
ファイル: UserLocal.cs プロジェクト: dmitrydnl/StashBot
        internal UserLocal(long chatId, string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Password cannot be null");
            }

            ISecureManager secureManager = ModulesManager.GetSecureManager();

            ChatId            = chatId;
            IsAuthorized      = false;
            hashPassword      = secureManager.CalculateHash(password);
            EncryptedPassword = null;
        }
コード例 #7
0
ファイル: UserLocal.cs プロジェクト: dmitrydnl/StashBot
        public bool ValidatePassword(string password)
        {
            ISecureManager secureManager = ModulesManager.GetSecureManager();

            return(secureManager.CompareWithHash(password, hashPassword));
        }