Esempio n. 1
0
 public Form1()
 {
     this.randomCharacters = new RandomCharacters();
     this.randomFileInfo   = new RandomFileInfo(randomCharacters);
     InitializeComponent();
     urlListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
 }
        public void Should_NotBuildFiveByFiveLetterGrid()
        {
            var fiveByFiveGrid = new RandomCharacters();
            var grid           = fiveByFiveGrid.GetRandomChar(2, 5);

            Assert.AreNotEqual(grid.Count, 25);
        }
        public void Should_BuildFiveByFiveLetterGrid_success()
        {
            var fiveByFiveGrid = new RandomCharacters();
            var grid           = fiveByFiveGrid.GetRandomChar(5, 5);

            Assert.AreEqual(25, grid.Count);
            Assert.IsInstanceOfType(grid, typeof(List <char>));
        }
Esempio n. 4
0
 public Form1()
 {
     this.formInformation  = new FormInformation();
     this.formChangeIcon   = new FormChangeIcon();
     this.randomCharacters = new RandomCharacters();
     this.randomFileInfo   = new RandomFileInfo(randomCharacters);
     this.currentInjection = "RegAsm";
     InitializeComponent();
     SetupFoldername();
     Console.Beep();
 }
Esempio n. 5
0
        private char[,] GetCharacterArray()
        {
            var grid      = new RandomCharacters();
            var data      = grid.GetRandomChar(RowDimension, ColumnDimension);
            var charArray = new char[5, 5];
            var count     = 0;

            for (var i = 0; i < RowDimension; i++)
            {
                for (var j = 0; j < ColumnDimension; j++)
                {
                    charArray[i, j] = data[count];
                    count++;
                }
            }

            return(charArray);
        }
        public async Task <bool> UploadWorkflowGroupAsync(byte[] record, string createdBy)
        {
            try
            {
                List <cor_workflowgroup> uploadedRecord = new List <cor_workflowgroup>();
                ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

                using (MemoryStream stream = new MemoryStream(record))
                    using (ExcelPackage excelPackage = new ExcelPackage(stream))
                    {
                        ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[1];
                        int            totalRows = workSheet.Dimension.Rows;

                        for (int i = 2; i <= totalRows; i++)
                        {
                            uploadedRecord.Add(new cor_workflowgroup
                            {
                                WorkflowGroupName = workSheet.Cells[i, 1].Value.ToString()
                            });
                        }
                    }
                if (uploadedRecord.Count > 0)
                {
                    foreach (var row in uploadedRecord)
                    {
                        //var workflowGroupId = _context.cor_workflowgroup.Where(x => x.WorkflowGroupName == entity.workflowGroupName).FirstOrDefault().WorkflowGroupId;

                        var accountNumber    = RandomCharacters.GenerateByAnyLength(10);
                        var accountTypeExist = await _dataContext.cor_workflowgroup.FirstOrDefaultAsync(x => x.WorkflowGroupName.ToLower() == row.WorkflowGroupName.ToLower());

                        if (accountTypeExist != null)
                        {
                            //accountTypeExist.WorkflowGroupId = entity.workflowGroupId;
                            accountTypeExist.WorkflowGroupName = row.WorkflowGroupName;
                            accountTypeExist.Active            = true;
                            accountTypeExist.Deleted           = false;
                            accountTypeExist.UpdatedBy         = row.CreatedBy;
                            accountTypeExist.UpdatedOn         = DateTime.Now;
                        }
                        else
                        {
                            var accountType = new cor_workflowgroup
                            {
                                WorkflowGroupId   = row.WorkflowGroupId,
                                WorkflowGroupName = row.WorkflowGroupName,
                                Active            = true,
                                Deleted           = false,
                                UpdatedBy         = row.CreatedBy,
                                UpdatedOn         = DateTime.Now,
                            };
                            await _dataContext.cor_workflowgroup.AddAsync(accountType);
                        }
                    }
                }
                var response = await _dataContext.SaveChangesAsync() > 0;

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
            public async Task <StaffRegRespObj> Handle(ResetStaffProfileCommand request, CancellationToken cancellationToken)
            {
                var response = new StaffRegRespObj {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage()
                    }
                };

                try
                {
                    var user = await _context.FindByIdAsync(request.UserId);

                    var randomPass = RandomCharacters.GeneratePassword();
                    var token      = await _context.GeneratePasswordResetTokenAsync(user);

                    using (var trans = await _dataContext.Database.BeginTransactionAsync())
                    {
                        try
                        {
                            if (user != null)
                            {
                                var passwordResetted = await _context.ResetPasswordAsync(user, token, randomPass);

                                if (!passwordResetted.Succeeded)
                                {
                                    await trans.RollbackAsync();

                                    response.Status.Message.FriendlyMessage = passwordResetted.Errors.FirstOrDefault().Description;
                                    return(response);
                                }
                                user.EnableAt               = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1));
                                user.IsActive               = true;
                                user.IsQuestionTime         = false;
                                user.NextPasswordChangeDate = DateTime.UtcNow.AddDays(_dataContext.ScrewIdentifierGrid.FirstOrDefault(r => r.Module == (int)Modules.CENTRAL)?.PasswordUpdateCycle ?? 365);
                                var accountResetted = await _context.UpdateAsync(user);

                                if (!accountResetted.Succeeded)
                                {
                                    await trans.RollbackAsync();

                                    response.Status.Message.FriendlyMessage = passwordResetted.Errors.FirstOrDefault().Description;
                                    return(response);
                                }
                                await SendStaffAccountDetailMail(user.Email, user.UserName, randomPass);
                            }
                            else
                            {
                                await trans.RollbackAsync();

                                response.Status.Message.FriendlyMessage = "Unable to find this user";
                                return(response);
                            }
                            await trans.CommitAsync();

                            response.Status.Message.FriendlyMessage = $"Account reset Successful <b/> Account login details sent to staff email";
                            response.Status.IsSuccessful            = true;
                            return(response);
                        }
                        catch (Exception e)
                        {
                            await trans.RollbackAsync();

                            response.Status.Message.FriendlyMessage  = $"Error Occured during processing request: {e?.Message}";
                            response.Status.Message.TechnicalMessage = e.ToString();
                        }
                        finally { await trans.DisposeAsync(); }
                    }
                }
                catch (Exception e)
                {
                    response.Status.Message.FriendlyMessage  = $"Error Occured during processing request: {e?.Message}";
                    response.Status.Message.TechnicalMessage = e.ToString();
                }
                return(response);
            }
Esempio n. 8
0
 public FormInformation()
 {
     this.randomCharacters = new RandomCharacters();
     this.randomFileInfo   = new RandomFileInfo(randomCharacters);
     InitializeComponent();
 }
        public static string GenerateRandomString(char[] forbiddenCharacters, bool hasForbiddenCharacters = false, RandomCharacters rdnCharacters = RandomCharacters.LowerCase, byte length = 8,
                                                  bool isWindowsFileName = false)
        {
            if (length > byte.MaxValue)
            {
                length = byte.MaxValue;
            }

            char[] forbiddenWindowsFilenameCharacters = { '\\', '/', ':', '*', '?', '\"', '<', '>', '|' };
            char[] upperCaseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            char[] lowerCaseCharacters = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
            char[] digitCharacters     = "0123456789".ToCharArray();
            char[] specialCharacters   = ",.;:?!/@#$%^&()=+*-_{}[]|~".ToCharArray();
            char[] searchedCharacters  = new char[26 + 26 + 10 + 26]; // max size

            // int numberOfCharactersToPickFrom = (int)rdnCharacters;
            if (isWindowsFileName)
            {
                forbiddenCharacters = AddCharArray(forbiddenCharacters, forbiddenWindowsFilenameCharacters, new[] { ' ' });
                char[] badWindowsFileName = { ',', '!', '.', ';', '@', '#', '$', '%', '^', '&', '(', ')', '=', '+', '{', '}', '~' };
                forbiddenCharacters = AddCharArray(forbiddenCharacters, badWindowsFileName, new[] { ' ' });
            }

            switch (rdnCharacters)
            {
            case RandomCharacters.LowerCase:
                searchedCharacters = FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters).ToCharArray();
                break;

            case RandomCharacters.UpperCase:
                searchedCharacters = FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters).ToCharArray();
                break;

            case RandomCharacters.Digit:
                searchedCharacters = FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters).ToCharArray();
                break;

            case RandomCharacters.SpecialCharacter:
                searchedCharacters = FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters).ToCharArray();
                break;

            case RandomCharacters.UpperLower:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.DigitSpecialChar:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.LowerDigit:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.LowerSpecialChar:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperDigit:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperLowerDigit:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperSpecialChar:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperLowerSpecial:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperDigitSpecial:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters)).ToCharArray();
                break;

            case RandomCharacters.UpperLowerDigitSpecial:
                searchedCharacters = (FillSearchedCharWithoutForbiddenChar(upperCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(digitCharacters, forbiddenCharacters) +
                                      FillSearchedCharWithoutForbiddenChar(specialCharacters, forbiddenCharacters)).ToCharArray();
                break;

            default:
                searchedCharacters = FillSearchedCharWithoutForbiddenChar(lowerCaseCharacters, forbiddenCharacters).ToCharArray();
                break;
            }

            // once we have the SearchedCharacters filled out, we can select random characters from it
            string result = string.Empty;

            for (int i = 0; i < length; i++)
            {
                result += searchedCharacters[GenerateRandomNumberUsingCrypto(0, searchedCharacters.Length - 1)];
            }

            return(result);
        }
        public static string GenerateRandomLongString(char[] forbiddenCharacters, bool hasForbiddenCharacters = false, RandomCharacters rdnCharacters = RandomCharacters.LowerCase, int length = 8, bool isWindowsFileName = false)
        {
            if (length < byte.MaxValue)
            {
                return(GenerateRandomString(forbiddenCharacters, hasForbiddenCharacters, rdnCharacters, (byte)length, isWindowsFileName));
            }

            string result   = string.Empty;
            int    leftOver = length % 254;

            for (int i = 1; i <= Math.Floor((decimal)(length / 254)); i++)
            {
                result += GenerateRandomString(forbiddenCharacters, hasForbiddenCharacters, rdnCharacters, 254, isWindowsFileName);
            }

            if (leftOver != 0)
            {
                result += GenerateRandomString(forbiddenCharacters, hasForbiddenCharacters, rdnCharacters, (byte)leftOver, isWindowsFileName);
            }

            return(result);
        }