diff --git a/Back/skydiveLogs-api.Business/UserService.cs b/Back/skydiveLogs-api.Business/UserService.cs index 5336c4f..d3d39ca 100644 --- a/Back/skydiveLogs-api.Business/UserService.cs +++ b/Back/skydiveLogs-api.Business/UserService.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; - -using skydiveLogs_api.Business.Interface; +using skydiveLogs_api.Business.Interface; using skydiveLogs_api.Model; using skydiveLogs_api.Data.Interface; - +using System.Security.Cryptography; +using System.Text; +using System.IO; +using System; namespace skydiveLogs_api.Business { @@ -17,16 +17,44 @@ namespace skydiveLogs_api.Business public User GetByLogin(string login, string password) { - var tmp = _userRepository.GetByLogin(login, password); + var tmp = _userRepository.GetByLogin(login, EncryptPassword(password)); return tmp; } public void AddNewUser(User newUser) { + newUser.Password = EncryptPassword(newUser.Password); _userRepository.Add(newUser); } + private string EncryptPassword(string password) + { + var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement + byte[] clearBytes = Encoding.Unicode.GetBytes(password); + var encryptedPassword = string.Empty; + + using (Aes encryptor = Aes.Create()) + { + Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey, + new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); + encryptor.Key = pdb.GetBytes(32); + encryptor.IV = pdb.GetBytes(16); + using (MemoryStream ms = new MemoryStream()) + { + using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) + { + cs.Write(clearBytes, 0, clearBytes.Length); + cs.Close(); + } + + encryptedPassword = Convert.ToBase64String(ms.ToArray()); + } + } + + return encryptedPassword; + } + private readonly IUserRepository _userRepository; } } diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index df5860b..a9bc297 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -25,12 +25,14 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); string connectionString = _configuration.GetConnectionString("DefaultConnection"); _services.AddSingleton(c => new Data.LiteDbProvider(connectionString)); diff --git a/Back/skydiveLogs-api/Controllers/UserController.cs b/Back/skydiveLogs-api/Controllers/UserController.cs index 96b9134..20dfb22 100644 --- a/Back/skydiveLogs-api/Controllers/UserController.cs +++ b/Back/skydiveLogs-api/Controllers/UserController.cs @@ -22,11 +22,11 @@ namespace skydiveLogs_api.Controllers } // POST: api/User - [HttpPost] + [HttpPost("Authenticate")] [EnableCors] - public UserResp Authenticate([FromBody] string login, [FromBody] string password) + public UserResp Authenticate([FromBody] UserReq value) { - var result = _userService.GetByLogin(login, password); + var result = _userService.GetByLogin(value.Login, value.Password); return _mapper.Map(result); } diff --git a/Back/skydiveLogs-api/Data/JumpsDb.db b/Back/skydiveLogs-api/Data/JumpsDb.db index ee60975..1bddf28 100644 Binary files a/Back/skydiveLogs-api/Data/JumpsDb.db and b/Back/skydiveLogs-api/Data/JumpsDb.db differ