diff --git a/AyCode.Entities/Locations/ILocationBase.cs b/AyCode.Entities/Locations/ILocationBase.cs new file mode 100644 index 0000000..96e0cb6 --- /dev/null +++ b/AyCode.Entities/Locations/ILocationBase.cs @@ -0,0 +1,11 @@ +using AyCode.Entities.Interfaces; +using AyCode.Interfaces.TimeStampInfo; + +namespace AyCode.Entities.Locations; + +public interface ILocationBase : IEntityGuid +{ + double Longitude { get; } + double Latitude { get; } + string? Address { get; } +} \ No newline at end of file diff --git a/AyCode.Entities/Locations/LocationBase.cs b/AyCode.Entities/Locations/LocationBase.cs new file mode 100644 index 0000000..a63ffc8 --- /dev/null +++ b/AyCode.Entities/Locations/LocationBase.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AyCode.Entities.Locations +{ + + + [Table("Locations")] + public class LocationBase : ILocationBase + { + public LocationBase() { } + + public LocationBase(double longitude, double latitude, string? address) : this(Guid.NewGuid(), longitude, latitude, address) { } + public LocationBase(Guid id, double longitude, double latitude , string address) : this() + { + Id = id; + Longitude = longitude; + Latitude = latitude; + Address = address; + } + + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] + public Guid Id { get; set; } + public double Longitude { get; set; } + public double Latitude { get; set; } + public string? Address { get; set; } + + } +} diff --git a/AyCode.Entities/Users/UserBase.cs b/AyCode.Entities/Users/UserBase.cs index d030b2c..a40c896 100644 --- a/AyCode.Entities/Users/UserBase.cs +++ b/AyCode.Entities/Users/UserBase.cs @@ -12,18 +12,40 @@ namespace AyCode.Entities.Users public class UserBase : IUserBase { public UserBase() { } + public UserBase(string email, string password) : this(Guid.NewGuid(), email, password) { } public UserBase(Guid id, string email, string password) : this() { Id = id; - Email = email; + Email = email; Password = password; } + public UserBase(string email, string phoneNumber, string password) : this(Guid.NewGuid(), email, phoneNumber, password) { } + public UserBase(Guid id, string email, string phoneNumber, string password) : this() + { + Id = id; + Email = email; + PhoneNumber = phoneNumber; + Password = password; + } + + public UserBase(string email, string phoneNumber, string password, string refreshToken) : this(Guid.NewGuid(), email, phoneNumber, password, refreshToken) { } + public UserBase(Guid id, string email, string phoneNumber, string password, string refreshToken) : this() + { + Id = id; + Email = email; + PhoneNumber = phoneNumber; + Password = password; + RefreshToken = refreshToken; + } + [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid Id { get; set; } public string Email { get; set; } + public string PhoneNumber { get; set; } public string Password { get; set; } + public string? RefreshToken { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } diff --git a/AyCode.Interfaces/MediaInfo/IMediaInfo.cs b/AyCode.Interfaces/MediaInfo/IMediaInfo.cs new file mode 100644 index 0000000..cbfd029 --- /dev/null +++ b/AyCode.Interfaces/MediaInfo/IMediaInfo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AyCode.Interfaces.MediaInfo +{ + internal interface IMediaInfo : IMediaThumbnailUrl, IMediaUserMediaId + { + } +} diff --git a/AyCode.Interfaces/MediaInfo/IMediaThumbnailUrl.cs b/AyCode.Interfaces/MediaInfo/IMediaThumbnailUrl.cs new file mode 100644 index 0000000..a9aebb0 --- /dev/null +++ b/AyCode.Interfaces/MediaInfo/IMediaThumbnailUrl.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AyCode.Interfaces.MediaInfo +{ + internal interface IMediaThumbnailUrl + { + } +} diff --git a/AyCode.Interfaces/MediaInfo/IMediaUserMediaId.cs b/AyCode.Interfaces/MediaInfo/IMediaUserMediaId.cs new file mode 100644 index 0000000..ef35a07 --- /dev/null +++ b/AyCode.Interfaces/MediaInfo/IMediaUserMediaId.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AyCode.Interfaces.MediaInfo +{ + internal interface IMediaUserMediaId + { + } +} diff --git a/AyCode.Interfaces/TimeStampInfo/TimeStampInfo.cs b/AyCode.Interfaces/TimeStampInfo/ITimeStampInfo.cs similarity index 100% rename from AyCode.Interfaces/TimeStampInfo/TimeStampInfo.cs rename to AyCode.Interfaces/TimeStampInfo/ITimeStampInfo.cs diff --git a/AyCode.Utils/AyCode.Utils.csproj b/AyCode.Utils/AyCode.Utils.csproj index 9413cb8..6fa67f3 100644 --- a/AyCode.Utils/AyCode.Utils.csproj +++ b/AyCode.Utils/AyCode.Utils.csproj @@ -8,6 +8,7 @@ + diff --git a/AyCode.Utils/Helpers/PasswordHasher.cs b/AyCode.Utils/Helpers/PasswordHasher.cs new file mode 100644 index 0000000..44433f3 --- /dev/null +++ b/AyCode.Utils/Helpers/PasswordHasher.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Cryptography.KeyDerivation; +using System.Security.Cryptography; + +namespace AyCode.Utils.Helpers +{ + public class PasswordHasher + { + public string HashPassword(string password) + { + // Generate a random salt + byte[] salt = new byte[16]; + using (var rng = RandomNumberGenerator.Create()) + { + rng.GetBytes(salt); + } + + // Hash the password with the salt + string hashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: password, + salt: salt, + prf: KeyDerivationPrf.HMACSHA512, + iterationCount: 10000, + numBytesRequested: 32)); + + // Combine the salt and hashed password + string combinedHash = $"$bcrypt$v=1$salt={Convert.ToBase64String(salt)}$hash={hashedPassword}"; + + return combinedHash; + } + + public bool VerifyPassword(string password, string hashedPassword) + { + // Extract the salt and hashed password from the combined hash + string[] parts = hashedPassword.Split('$'); + byte[] salt = Convert.FromBase64String(parts[3]); + string storedHash = parts[5]; + + // Hash the provided password with the extracted salt + string hashedProvidedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: password, + salt: salt, + prf: KeyDerivationPrf.HMACSHA512, + iterationCount: 10000, + numBytesRequested: 32)); + + // Compare the hashed passwords + return storedHash == hashedProvidedPassword; + } + } +} + +