Skip to content

Commit

Permalink
analizators/SCS0005
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 10, 2022
1 parent d7a1f73 commit a671732
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions common/ASC.Common/Utils/RandomString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


using System;
using System.Security.Cryptography;
using System.Text;

namespace ASC.Common.Utils
Expand All @@ -35,10 +36,9 @@ public static string Generate(int length)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
var res = new StringBuilder();
var rnd = new Random();
while (0 < length--)
{
res.Append(valid[rnd.Next(valid.Length)]);
res.Append(valid[RandomNumberGenerator.GetInt32(valid.Length)]);
}
return res.ToString();
}
Expand Down
5 changes: 2 additions & 3 deletions common/ASC.Core.Common/Encryption/EncryptionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,15 @@ public string GeneratePassword(int length, int numberOfNonAlphanumericCharacters

if (num < numberOfNonAlphanumericCharacters)
{
var random = new Random();
for (var j = 0; j < numberOfNonAlphanumericCharacters - num; j++)
{
int num3;
do
{
num3 = random.Next(0, length);
num3 = RandomNumberGenerator.GetInt32(0, length);
}
while (!char.IsLetterOrDigit(array2[num3]));
array2[num3] = punctuations[random.Next(0, punctuations.Length)];
array2[num3] = punctuations[RandomNumberGenerator.GetInt32(0, punctuations.Length)];
}
}

Expand Down
5 changes: 2 additions & 3 deletions common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -776,9 +777,7 @@ public override string UploadChunk(string domain,

for (var i = 0; i < MAX_RETRIES; i++)
{
var random = new Random();

millisecondsTimeout = Math.Min(Convert.ToInt32(Math.Pow(2, i)) + random.Next(0, 1000), 32 * 1000);
millisecondsTimeout = Math.Min(Convert.ToInt32(Math.Pow(2, i)) + RandomNumberGenerator.GetInt32(1000), 32 * 1000);

try
{
Expand Down
2 changes: 1 addition & 1 deletion products/ASC.Files/Core/Model/FileWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static FileWrapper<int> GetSample()
//Updated = ApiDateTime.GetSample(),
//Created = ApiDateTime.GetSample(),
//CreatedBy = EmployeeWraper.GetSample(),
Id = new Random().Next(),
Id = 10,
RootFolderType = FolderType.BUNCH,
Shared = false,
Title = "Some titile.txt",
Expand Down
8 changes: 4 additions & 4 deletions products/ASC.Files/Core/Model/FolderWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public static FolderWrapper<int> GetSample()
//Updated = ApiDateTime.GetSample(),
//Created = ApiDateTime.GetSample(),
//CreatedBy = EmployeeWraper.GetSample(),
Id = new Random().Next(),
Id = 10,
RootFolderType = FolderType.BUNCH,
Shared = false,
Title = "Some titile",
//UpdatedBy = EmployeeWraper.GetSample(),
FilesCount = new Random().Next(),
FoldersCount = new Random().Next(),
ParentId = new Random().Next(),
FilesCount = 5,
FoldersCount = 7,
ParentId = 10,
IsShareable = null
};
}
Expand Down
3 changes: 2 additions & 1 deletion web/ASC.Web.Core/Sms/SmsKeyStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Cryptography;

using ASC.Common;
using ASC.Common.Caching;
Expand Down Expand Up @@ -120,7 +121,7 @@ public bool GenerateKey(string phone, out string key)
return false;
}

key = new Random().Next((int)Math.Pow(10, KeyLength - 1), (int)Math.Pow(10, KeyLength)).ToString(CultureInfo.InvariantCulture);
key = RandomNumberGenerator.GetInt32((int)Math.Pow(10, KeyLength - 1), (int)Math.Pow(10, KeyLength)).ToString(CultureInfo.InvariantCulture);
phoneKeys[key] = DateTime.UtcNow;

KeyCache.Insert(cacheKey, phoneKeys, DateTime.UtcNow.Add(StoreInterval));
Expand Down
7 changes: 3 additions & 4 deletions web/ASC.Web.Core/Users/UserManagerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Globalization;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -294,16 +295,14 @@ public static string GeneratePassword()
return Guid.NewGuid().ToString();
}

private static readonly Random Rnd = new Random();

internal static string GeneratePassword(int minLength, int maxLength, string noise)
{
var length = Rnd.Next(minLength, maxLength + 1);
var length = RandomNumberGenerator.GetInt32(minLength, maxLength + 1);

var pwd = string.Empty;
while (length-- > 0)
{
pwd += noise.Substring(Rnd.Next(noise.Length - 1), 1);
pwd += noise.Substring(RandomNumberGenerator.GetInt32(noise.Length - 1), 1);
}
return pwd;
}
Expand Down

0 comments on commit a671732

Please sign in to comment.