This repository was archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
76 lines (66 loc) · 2.67 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.IO;
using DevOne.Security.Cryptography.BCrypt;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace musicList2
{
public class Program
{
public static void Main(string[] args)
{
// Pasre command line args to config on startup
var argConf = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
// If config includes 'generateKeyHash', the program will
// generate a hash of the passed key based on the passed
// parameters and then exit the program with 0 without
// actually starting the web server.
if (argConf["generateKeyHash"] != null)
{
var rounds = argConf.GetValue<int>("hashRounds");
rounds = rounds > 0 ? rounds : 12;
var salt = BCryptHelper.GenerateSalt(rounds);
Console.WriteLine(
"Generating Hash of passed keyword...\n\n" +
$"Hash Rounds: {rounds}\n" +
$"Using Salt: {salt}");
var hash = BCryptHelper.HashPassword(argConf["generateKeyHash"], salt);
Console.WriteLine($"Generated Hash: ${hash}");
return;
}
// Start the web server
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true)
.AddEnvironmentVariables(prefix: "ML_")
.AddCommandLine(args)
.Build();
return new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseConfiguration(config)
.UseUrls(config["Server:URL"])
.UseDefaultServiceProvider((context, options) =>
{
options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
})
.ConfigureLogging((hostingContext, logging) =>
{
logging
.AddConfiguration(hostingContext.Configuration.GetSection("Logging"))
.AddConsole()
.AddDebug()
.AddEventSourceLogger();
})
.UseStartup<Startup>();
}
}
}