using System.Collections.Generic;
using System.Security.Cryptography;
public class RegistrationSystem
private static bool _enableLinkInvitation;
private static bool _requireConfirmation;
private static Dictionary<string, User> _userConfirmations = new Dictionary<string, User>();
public static Uri SetLinkInvitationSetting(bool enableLinkInvitation, bool requireConfirmation)
_enableLinkInvitation = enableLinkInvitation;
_requireConfirmation = requireConfirmation;
if (enableLinkInvitation)
return new Uri("https://example.com/register");
public static class Account
public static Uri GetRegistrationConfirmUri(User user)
string token = GenerateConfirmationToken();
_userConfirmations[token] = user;
return new Uri($"https://example.com/confirm?token={token}");
private static string GenerateConfirmationToken()
using (var rng = new RNGCryptoServiceProvider())
var tokenBytes = new byte[32];
rng.GetBytes(tokenBytes);
return Convert.ToBase64String(tokenBytes);
public static void JoinPortalNewUser(User user, Uri confirmUri, bool expectConfirmationPage)
Console.WriteLine($"User {user.Email} opening confirmation link: {confirmUri}");
if (expectConfirmationPage)
Console.WriteLine("Confirmation page displayed.");
string token = confirmUri.Query.Substring(confirmUri.Query.IndexOf("token=") + 6);
if (_userConfirmations.ContainsKey(token))
User confirmingUser = _userConfirmations[token];
confirmingUser.IsConfirmed = true;
_userConfirmations.Remove(token);
Console.WriteLine($"User confirmed: {confirmingUser.Email}");
Console.WriteLine($"Confirmation Failed. Token {token} is invalid");
public static void RejectUsrInvitationWithAssertAuthImpossabilityCommonPart(User user)
RejectUserInvitCommon(user);
Console.WriteLine($"Login attempt failed for user: {user.Email}");
public static void RejectUserInvitCommon(User user)
Console.WriteLine($"User {user.Email} Rejected Invitation");
public static string getTextForRegCompletePage()
return "Registration Complete!";
public string Email { get; set; }
public string Password { get; set; }
public bool IsConfirmed { get; set; }
public bool IsRejected {get; set;}
public static void Main(string[] args)
Uri invitationLink = SetLinkInvitationSetting(true, true);
Console.WriteLine($"Invitation Link: {invitationLink}");
User newUser = new User { Email = "testuser@example.com", Password = "Password123" };
Uri confirmUri = Account.GetRegistrationConfirmUri(newUser);
JoinPortalNewUser(newUser, confirmUri, true);
RejectUsrInvitationWithAssertAuthImpossabilityCommonPart(newUser);
if(newUser.IsConfirmed && newUser.IsRejected)
Console.WriteLine(getTextForRegCompletePage());