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>
       </div>
       <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>
         </div>
       <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>
         </div>

       </div>
    <!--   <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>
     </form>

And My php file, addusers.php:

 <?php

include(“session.php”);
include(“config.php”);

if(isset($_POST[‘btn-add’])){
// basic name validation
$name=$_POST[‘name’];
// $name1=$name;

$pass=$_POST['pass'];

$masterpass=$_POST[‘masterpass’];
$passwordm = hash(‘sha256’, $masterpass);
$passwordm=MD5($passwordm);

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

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

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

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:

https://docs.nextcloud.com/server/12/admin_manual/configuration_server/occ_command.html#user-commands

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