mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 15:01:56 +00:00
Added LDAP migrations, made CreateObject async, moved LdapOptions to Models, fixed user password not hashed on user creation
This commit is contained in:
@@ -3,6 +3,8 @@ using Berufsschule_HAM.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Novell.Directory.Ldap;
|
||||
using Berufsschule_HAM.Models;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
[Route("[controller]")]
|
||||
public class UsersController : Controller
|
||||
@@ -58,7 +60,7 @@ public class UsersController : Controller
|
||||
}
|
||||
|
||||
[HttpGet("Create")]
|
||||
public bool Create(string cn, string sn, string? title, string? uid, string userPassword, string? description, string jpegPhoto)
|
||||
public async Task<bool> Create(string cn, string sn, string? title, string? uid, string userPassword, string? description, string jpegPhoto)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -66,8 +68,14 @@ public class UsersController : Controller
|
||||
uid ??= sn.ToLower() + cn.ToLower();
|
||||
title ??= "";
|
||||
description ??= "{}";
|
||||
LdapAttributeSet attributeSet = new LdapAttributeSet
|
||||
if (!userPassword.StartsWith('{'))
|
||||
{
|
||||
byte[] passwordBytes = Encoding.UTF8.GetBytes(userPassword);
|
||||
byte[] hashedPassword = SHA256.HashData(passwordBytes);
|
||||
userPassword = "{SHA256}" + Convert.ToBase64String(hashedPassword);
|
||||
}
|
||||
LdapAttributeSet attributeSet =
|
||||
[
|
||||
new LdapAttribute("objectClass", "inetOrgPerson"),
|
||||
new LdapAttribute("cn", cn),
|
||||
new LdapAttribute("sn", sn),
|
||||
@@ -76,8 +84,8 @@ public class UsersController : Controller
|
||||
new LdapAttribute("jpegPhoto", jpegPhoto),
|
||||
new LdapAttribute("description", description),
|
||||
new LdapAttribute("userPassword", userPassword)
|
||||
};
|
||||
_ldap.CreateUser(uid, attributeSet);
|
||||
];
|
||||
await _ldap.CreateUser(uid, attributeSet);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user