Add User to NextCloud using PHP

Hello, I have 2 servers now, and i have 2 diffrent logins on it, i have made so a button could switch between the servers and an autologin, but how do i add users to both of them? I have made an add user form and it works, but it adds a user to only the 1st server (both of them are using mysql) and if you want to add a user to nextcloud, you have to do it manually. How do you add an account to nextcloud? Which database it uses for users and how does it encrypt passwords (if i could get that info)? My add user form:

<form class="col s12" method="post" action="../php/adduser.php">
       <div class="row">
         <div class="input-field col s6">
           <input id="first_name" type="text" class="validate" autocomplete="off" name="name">
           <label for="first_name">Username</label>
       <div class="row">
         <div class="input-field col s6">
           <input id="password" type="password" class="validate" autocomplete="off" name="pass">
           <label for="password">Password</label>
       <div class="row">
         <div class="input-field col s6">
           <input id="msterpasword" type="password" class="validate" autocomplete="off" name="masterpass">
           <label for="password">Master Password</label>

    <!--   <input type="submit" value="Add User" class="waves-effect waves-light btn user" name="button-add"/>-->
       <button type="submit" class="waves-effect waves-light btn user" name="btn-add">Add User</button>

And My php file, addusers.php:



// basic name validation
// $name1=$name;


$passwordm = hash(‘sha256’, $masterpass);

if ($_POST[‘masterpass’]==“zerouser”) {

// password encrypt using SHA256();
$password = hash(‘sha256’, $pass);

	$sql = "INSERT INTO login(username,password) VALUES('$name','$password')";

header(“Location: …/pages/options.php”);

} else {
$fmsg = “Master Password does not match”;
header(“Location: …/pages/options.php”);

Have you ever considered some sort of cloud federation? Also, there are built-in commands for user management:

I did not see them, thank you!

Hi Pault. I am also interested in this part.
Can you tell me more when you have tested this and how you set this up?

Thank you