Initial commit
This commit is contained in:
64
Utils/PasswordHash.cs
Executable file
64
Utils/PasswordHash.cs
Executable file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class PasswordHash
|
||||
{
|
||||
private static Random random = new Random();
|
||||
|
||||
public static byte[] getNextSalt()
|
||||
{
|
||||
byte[] salt = new byte[20];
|
||||
random.NextBytes(salt);
|
||||
return salt;
|
||||
}
|
||||
|
||||
public static byte[] Hash(string password, byte[] salt)
|
||||
{
|
||||
HashAlgorithm algorithm = new SHA256Managed();
|
||||
|
||||
byte[] bytePassword = Encoding.UTF8.GetBytes(password);
|
||||
byte[] plainTextWithSaltBytes = new byte[bytePassword.Length + salt.Length];
|
||||
|
||||
for (int i = 0; i < bytePassword.Length; i++)
|
||||
{
|
||||
plainTextWithSaltBytes[i] = bytePassword[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < salt.Length; i++)
|
||||
{
|
||||
plainTextWithSaltBytes[bytePassword.Length + i] = salt[i];
|
||||
}
|
||||
|
||||
return algorithm.ComputeHash(plainTextWithSaltBytes);
|
||||
}
|
||||
|
||||
public static bool Compare(string password, byte[] salt, byte[] hashed)
|
||||
{
|
||||
if (password == null) return false;
|
||||
if (hashed == null) return false;
|
||||
|
||||
byte[] hashedNew = Hash(password, salt);
|
||||
|
||||
if (hashedNew.Length != hashed.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < hashedNew.Length; i++)
|
||||
{
|
||||
if (hashedNew[i] != hashed[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Utils/Properties/AssemblyInfo.cs
Executable file
36
Utils/Properties/AssemblyInfo.cs
Executable file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// La información general de un ensamblado se controla mediante el siguiente
|
||||
// conjunto de atributos. Cambie estos valores de atributo para modificar la información
|
||||
// asociada con un ensamblado.
|
||||
[assembly: AssemblyTitle("Utils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Utils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles
|
||||
// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde
|
||||
// COM, establezca el atributo ComVisible en true en este tipo.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM.
|
||||
[assembly: Guid("8e925c93-1efc-455f-b5f1-af46df4a23bf")]
|
||||
|
||||
// La información de versión de un ensamblado consta de los cuatro valores siguientes:
|
||||
//
|
||||
// Versión principal
|
||||
// Versión secundaria
|
||||
// Número de compilación
|
||||
// Revisión
|
||||
//
|
||||
// Puede especificar todos los valores o usar los números de compilación y de revisión predeterminados
|
||||
// mediante el carácter "*", como se muestra a continuación:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
54
Utils/Utils.csproj
Executable file
54
Utils/Utils.csproj
Executable file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8E925C93-1EFC-455F-B5F1-AF46DF4A23BF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Utils</RootNamespace>
|
||||
<AssemblyName>Utils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Markdown, Version=2.0.0.0, Culture=neutral, PublicKeyToken=1b320cc08ad5aa89, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Markdown.2.2.1\lib\net451\Markdown.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PasswordHash.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
BIN
Utils/bin/Debug/Markdown.dll
Executable file
BIN
Utils/bin/Debug/Markdown.dll
Executable file
Binary file not shown.
BIN
Utils/bin/Debug/Utils.dll
Executable file
BIN
Utils/bin/Debug/Utils.dll
Executable file
Binary file not shown.
BIN
Utils/bin/Debug/Utils.pdb
Executable file
BIN
Utils/bin/Debug/Utils.pdb
Executable file
Binary file not shown.
BIN
Utils/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Executable file
BIN
Utils/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Executable file
Binary file not shown.
0
Utils/obj/Debug/Utils.csproj.CopyComplete
Executable file
0
Utils/obj/Debug/Utils.csproj.CopyComplete
Executable file
1
Utils/obj/Debug/Utils.csproj.CoreCompileInputs.cache
Executable file
1
Utils/obj/Debug/Utils.csproj.CoreCompileInputs.cache
Executable file
@@ -0,0 +1 @@
|
||||
b04b0ef0a3d8170021e4a6f84cd68bf1addde2d1
|
||||
8
Utils/obj/Debug/Utils.csproj.FileListAbsolute.txt
Executable file
8
Utils/obj/Debug/Utils.csproj.FileListAbsolute.txt
Executable file
@@ -0,0 +1,8 @@
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\bin\Debug\Utils.dll
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\bin\Debug\Utils.pdb
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\bin\Debug\Markdown.dll
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\obj\Debug\Utils.csprojAssemblyReference.cache
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\obj\Debug\Utils.csproj.CoreCompileInputs.cache
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\obj\Debug\Utils.csproj.CopyComplete
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\obj\Debug\Utils.dll
|
||||
C:\Users\dell\source\repos\Proyecto\Utils\obj\Debug\Utils.pdb
|
||||
BIN
Utils/obj/Debug/Utils.csprojAssemblyReference.cache
Executable file
BIN
Utils/obj/Debug/Utils.csprojAssemblyReference.cache
Executable file
Binary file not shown.
BIN
Utils/obj/Debug/Utils.dll
Executable file
BIN
Utils/obj/Debug/Utils.dll
Executable file
Binary file not shown.
BIN
Utils/obj/Debug/Utils.pdb
Executable file
BIN
Utils/obj/Debug/Utils.pdb
Executable file
Binary file not shown.
4
Utils/packages.config
Executable file
4
Utils/packages.config
Executable file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Markdown" version="2.2.1" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user