first commit

This commit is contained in:
Your Name 2026-01-21 00:23:28 +03:00
commit 1530450313
165 changed files with 8443 additions and 0 deletions

30
src/AuthApp.csproj Normal file
View file

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- ============================= -->
<!-- Общие настройки проекта -->
<!-- ============================= -->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<!-- ============================= -->
<!-- Настройки Release -->
<!-- ============================= -->
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Optimize>true</Optimize>
<DebugType>none</DebugType>
</PropertyGroup>
<!-- ============================= -->
<!-- Настройки Debug -->
<!-- ============================= -->
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<Optimize>false</Optimize>
<DebugType>portable</DebugType>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,25 @@
using AuthApp.Data;
using AuthApp.Utils;
/// <summary>
/// Сервис аутентификации
/// </summary>
namespace AuthApp.Services
{
public class AuthService
{
private readonly UserRepository _repository = new();
/// <summary>
/// Проверка логина и пароля
/// </summary>
public bool Authenticate(string login, string password)
{
var user = _repository.GetUser(login);
if (user == null) return false;
string hash = PasswordHasher.Hash(password);
return (user.PasswordHash == hash);
}
}
}

View file

@ -0,0 +1,18 @@
namespace AuthApp.Models
{
/// <summary>
/// Модель пользователя системы.
/// </summary>
public class User
{
/// <summary>
/// Логин пользователя.
/// </summary>
public string Login { get; set; } = string.Empty;
/// <summary>
/// Хэш пароля пользователя.
/// </summary>
public string PasswordHash { get; set; } = string.Empty;
}
}

56
src/AuthApp/Program.cs Normal file
View file

@ -0,0 +1,56 @@
using AuthApp.Services;
using AuthApp.Utils;
using AuthApp.Data;
using System;
using System.Threading;
/// <summary>
/// Entry point приложения
/// </summary>
class Program
{
static void Main()
{
var authService = new AuthService();
int attempts = 0;
const int maxAttempts = 3;
var repo = new UserRepository();
if (!repo.IsDatabaseAvailable())
{
Console.WriteLine("Невозможно найти users.json. Проверьте путь или рабочую директорию.");
Thread.Sleep(20000);
return;
}
while (attempts < maxAttempts)
{
Console.Clear();
Console.WriteLine("=== Authentication System ===");
Console.Write("Login: ");
string login = Console.ReadLine() ?? "";
Console.Write("Password: ");
string password = ConsoleHelper.ReadPassword();
bool success = authService.Authenticate(login, password);
if (success)
{
Console.WriteLine("\nAccess granted.");
return;
}
attempts++;
Console.WriteLine("\nAccess denied.");
if (attempts < maxAttempts)
{
Console.WriteLine("Press any key to retry...");
Console.ReadKey();
}
}
Console.WriteLine("\nToo many failed attempts. Access blocked.");
}
}

View file

@ -0,0 +1,56 @@
using System.Text.Json;
using AuthApp.Models;
using AuthApp.Utils;
namespace AuthApp.Data
{
/// <summary>
/// Репозиторий пользователей.
/// Отвечает за загрузку данных пользователей из хранилища.
/// </summary>
public class UserRepository
{
private static readonly string DatabasePath = Path.Combine(AppContext.BaseDirectory, "../data/users.json");
public bool IsDatabaseAvailable()
{
string fullPath = Path.GetFullPath(DatabasePath);
bool exists = File.Exists(fullPath);
if (exists)
{
Console.WriteLine($"✅ Database file found: {fullPath}");
}
else
{
Console.WriteLine($"❌ Database file NOT found: {fullPath}");
}
return exists;
}
/// <summary>
/// Получает пользователя по логину.
/// </summary>
/// <param name="login">Логин пользователя</param>
/// <returns>
/// Объект <see cref="User"/>, если пользователь найден,
/// иначе <c>null</c>.
/// </returns>
public User? GetUser(string login)
{
if (string.IsNullOrWhiteSpace(login))
return null;
if (!File.Exists(DatabasePath))
return null;
var json = File.ReadAllText(DatabasePath);
var users = JsonSerializer.Deserialize<List<User>>(json);
return users?.FirstOrDefault(u =>
string.Equals(u.Login, login, StringComparison.OrdinalIgnoreCase));
}
}
}

View file

@ -0,0 +1,33 @@
namespace AuthApp.Utils
{
/// <summary>
/// Вспомогательные функции консоли
/// </summary>
public static class ConsoleHelper
{
public static string ReadPassword()
{
string password = "";
ConsoleKeyInfo keyInfo;
while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Enter)
{
char keyChar = keyInfo.KeyChar;
if (keyInfo.Key == ConsoleKey.Backspace && password.Length > 0)
{
password = password[..^1];
Console.Write("\b \b");
}
else if (!char.IsControl(keyChar))
{
password += keyChar;
Console.Write("*");
}
}
return password;
}
}
}

View file

@ -0,0 +1,32 @@
using System.Security.Cryptography;
using System.Text;
namespace AuthApp.Utils
{
/// <summary>
/// Утилита для хэширования паролей.
/// </summary>
public static class PasswordHasher
{
/// <summary>
/// Вычисляет SHA-256 хэш для пароля.
/// </summary>
/// <param name="password">Пароль в открытом виде</param>
/// <returns>Строка с хэшем в hex-формате</returns>
public static string Hash(string password)
{
if (password == null)
return string.Empty;
using var sha256 = SHA256.Create();
byte[] bytes = Encoding.UTF8.GetBytes(password);
byte[] hash = sha256.ComputeHash(bytes);
var sb = new StringBuilder();
foreach (byte b in hash)
sb.Append(b.ToString("x2"));
return sb.ToString();
}
}
}

View file

@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"/home/ars/is_proj/src/App.csproj": {}
},
"projects": {
"/home/ars/is_proj/src/App.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/ars/is_proj/src/App.csproj",
"projectName": "App",
"projectPath": "/home/ars/is_proj/src/App.csproj",
"packagesPath": "/home/ars/.nuget/packages/",
"outputPath": "/home/ars/is_proj/src/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/ars/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.417/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/ars/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/ars/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/ars/.nuget/packages/" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View file

@ -0,0 +1,66 @@
{
"format": 1,
"restore": {
"/home/ars/is_proj/src/AuthApp.csproj": {}
},
"projects": {
"/home/ars/is_proj/src/AuthApp.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/ars/is_proj/src/AuthApp.csproj",
"projectName": "AuthApp",
"projectPath": "/home/ars/is_proj/src/AuthApp.csproj",
"packagesPath": "/home/ars/.nuget/packages/",
"outputPath": "/home/ars/is_proj/src/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/ars/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.417/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/ars/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/ars/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/ars/.nuget/packages/" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View file

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View file

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("App")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("App")]
[assembly: System.Reflection.AssemblyTitleAttribute("App")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -0,0 +1 @@
92c167b5d8c056866ba4b0cbf5e77a09dcd3846aedbf7fb6513d30860b4fe153

View file

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = App
build_property.ProjectDir = /home/ars/is_proj/src/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View file

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View file

@ -0,0 +1 @@
9f909757170634c4a1bcf2b07ca1d394645ac058b5f80d65e2307ce2f736dbf6

View file

@ -0,0 +1,4 @@
/home/ars/is_proj/src/obj/Release/net8.0/App.GeneratedMSBuildEditorConfig.editorconfig
/home/ars/is_proj/src/obj/Release/net8.0/App.AssemblyInfoInputs.cache
/home/ars/is_proj/src/obj/Release/net8.0/App.AssemblyInfo.cs
/home/ars/is_proj/src/obj/Release/net8.0/App.csproj.CoreCompileInputs.cache

View file

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("AuthApp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("AuthApp")]
[assembly: System.Reflection.AssemblyTitleAttribute("AuthApp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -0,0 +1 @@
292cf9dcf31ff2612c58ac08730d86c89331d58a7d5ee2648b6e8ae869023ded

View file

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = AuthApp
build_property.ProjectDir = /home/ars/is_proj/src/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View file

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View file

@ -0,0 +1 @@
1cebe11aa37d819318f2cb5f3b7643f5022fec8a8184deddfd78f1edb954d93d

View file

@ -0,0 +1,12 @@
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.GeneratedMSBuildEditorConfig.editorconfig
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.AssemblyInfoInputs.cache
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.AssemblyInfo.cs
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.csproj.CoreCompileInputs.cache
/home/ars/is_proj/build/AuthApp
/home/ars/is_proj/build/AuthApp.deps.json
/home/ars/is_proj/build/AuthApp.runtimeconfig.json
/home/ars/is_proj/build/AuthApp.dll
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.dll
/home/ars/is_proj/src/obj/Release/net8.0/refint/AuthApp.dll
/home/ars/is_proj/src/obj/Release/net8.0/AuthApp.genruntimeconfig.cache
/home/ars/is_proj/src/obj/Release/net8.0/ref/AuthApp.dll

Binary file not shown.

View file

@ -0,0 +1 @@
a49dddb432e4a3841a93b9a8185168f5eda44a87cab9f503a863dd05557471c3

BIN
src/obj/Release/net8.0/apphost Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,71 @@
{
"version": 3,
"targets": {
"net8.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
},
"packageFolders": {
"/home/ars/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/ars/is_proj/src/AuthApp.csproj",
"projectName": "AuthApp",
"projectPath": "/home/ars/is_proj/src/AuthApp.csproj",
"packagesPath": "/home/ars/.nuget/packages/",
"outputPath": "/home/ars/is_proj/src/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/ars/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.417/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View file

@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "6eiPzm/BFTQ=",
"success": true,
"projectFilePath": "/home/ars/is_proj/src/AuthApp.csproj",
"expectedPackageFiles": [],
"logs": []
}