All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.eliux.mega.cmd.MegaCmdChangePassword Maven / Gradle / Ivy

Go to download

Java client library that works on top of MEGAcmd to provide access to the services of Mega.nz

There is a newer version: 1.6.2
Show newest version
package io.github.eliux.mega.cmd;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

public class MegaCmdChangePassword extends AbstractMegaCmdRunnerWithParams {

    private final String oldPassword;

    private final String newPassword;

    private Optional authCode;

    public MegaCmdChangePassword(String oldPassword, String newPassword) {
        this.oldPassword = oldPassword;
        this.newPassword = newPassword;
        authCode = Optional.empty();
    }

    @Override
    List cmdParams() {
        final List cmdParams = new LinkedList<>();

        cmdParams.add(oldPassword);

        cmdParams.add("-f");

        authCode.ifPresent(ac -> {
            cmdParams.add(String.format("--auth-code=%s", ac));
        });

        cmdParams.add(newPassword);

        return cmdParams;
    }

    @Override
    public String getCmd() {
        return "passwd";
    }

    public String getOldPassword() {
        return oldPassword;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public MegaCmdChangePassword setAuthCode(String authCode) {
        this.authCode = Optional.of(authCode);
        return this;
    }

    public MegaCmdChangePassword removeAuthCode() {
        this.authCode = Optional.empty();
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy