Password processing

Report a typo

The UserProfile class is supposed to represent a user in a social network. It has the following fields:

class UserProfile implements Serializable {

    private String login;
    private String email;
    private transient String password;

    // a constructor and getters
}

You need to implement custom serialization and deserialization for objects of this class (see the methods readObject and writeObject).

The serialization should save the fields login and email as is and encrypt the password field. The encryption algorithm is very simple and we use it only for education purposes: each char of the string is shifted by 1 position according to the unicode table (i.e. 123 -> 234, abc -> bcd). The deserialization should perform a reverse process to restore the original password.

Write a program in Java 17
class UserProfile implements Serializable {
private static final long serialVersionUID = 26292552485L;

private String login;
private String email;
private transient String password;

public UserProfile(String login, String email, String password) {
this.login = login;
this.password = password;
this.email = email;
}

// implement readObject and writeObject properly

public String getLogin() {
return login;
}

public String getPassword() {
return password;
}

public String getEmail() {
return email;
}
}
___

Create a free account to access the full topic