2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.asuswrt.internal.structures;
15 import java.util.Base64;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * This class is used for storing Asuswrt credentials.
22 * @author Christian Wild - Initial contribution
25 public class AsuswrtCredentials {
26 private String username = "";
27 private String password = "";
28 private String encodedCredentials = "";
30 public AsuswrtCredentials() {
33 public AsuswrtCredentials(AsuswrtConfiguration routerConfig) {
34 setCredentials(routerConfig.username, routerConfig.password);
37 public AsuswrtCredentials(String username, String password) {
38 setCredentials(username, password);
46 * Stores the given credentials.
48 private void setCredentials(String username, String password) {
49 this.username = username;
50 this.password = password;
51 encodedCredentials = b64encode(username + ":" + password);
55 * Encodes a String using Base64.
57 private String b64encode(String string) {
58 return Base64.getEncoder().encodeToString((string).getBytes());
66 * Returns Base64 encoded credentials.
68 * @return 'username:password' as Base64 encoded string
70 public String getEncodedCredentials() {
71 return encodedCredentials;
74 public String getPassword() {
78 public String getUsername() {