Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mircea Teodor Oprea Mirch

🎯
Focusing
Block or report user

Report or block Mirch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Stack.cs
public interface IStack
{
void Push(StackNode node);
StackNode Pop();
}
public class Stack : IStack
{
private LinkedList<StackNode> _elements;
View Duplicates.cs
bool HasDuplicates(int[] items)
{
HashSet<int> appearances = new HashSet<int>();
for (int i = 0; i < items.Length; i++)
{
if (!appearances.Add(items[i]))
{
return true;
}
View TokenService.cs
public class TokenService : ITokenService
{
private readonly AuthenticationSettings _authenticationSettings;
public TokenService(IOptions<AuthenticationSettings> authenticationSettings)
{
_authenticationSettings = authenticationSettings.Value;
}
public string BuildToken(string email, string role = "User")
View ITokenService.cs
public interface ITokenService
{
string BuildToken(string email, string role = "User");
}
View ProjectTypesController.cs
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Admin")]
[HttpPost]
public async Task<IActionResult> CreateProjectType([FromBody] ProjectType model)
{
View AuthenticationController.cs
[HttpPost("login")]
public IActionResult Login([FromBody]UserCredentials credentials)
{
var user = _context.Users.SingleOrDefault(u => u.Email == credentials.Email);
if (user != null)
{
var hashedPassword = _hashingService.Hash(credentials.Password, user.Salt);
if (hashedPassword == user.HashedPassword)
View AuthenticationController.cs
[HttpPost("register")]
public async Task<IActionResult> Register([FromBody]UserCredentials credentials)
{
var alreadyExists = _context.Users.Any(u => u.Email == credentials.Email);
if (alreadyExists)
{
return BadRequest("User already exists.");
}
View User.cs
public struct UserCredentials
{
public string Email { get; set; }
public string Password { get; set; }
}
View AuthenticationController.cs
private string BuildToken(string email)
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.UTF8.GetBytes(_authenticationSettings.JwtKey);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, email)
View AuthenticationController.cs
[Route("/auth/")]
public class AuthenticationController : ControllerBase
{
private readonly BlueInkDbContext _context;
private readonly HashingService _hashingService;
private readonly ITokenService _tokenService;
public AuthenticationController(BlueInkDbContext context,
HashingService hashingService,
ITokenService tokenService)
You can’t perform that action at this time.