X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fdemoscenemusic%2Fdata%2FDefaultUser.java;h=fb2836c2bfe5da0760833fd5ada3b26129d3a215;hb=6044000b16b448b4f1f6df4dd9b101ceed2397ac;hp=ea2959ccf483e147944bdabd54c1ce539bfdca4c;hpb=efcd05460aea3a517d03d1b36fd6ff81ac7cf12e;p=demoscenemusic.git diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultUser.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultUser.java index ea2959c..fb2836c 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultUser.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DefaultUser.java @@ -17,8 +17,11 @@ package net.pterodactylus.demoscenemusic.data; +import java.io.UnsupportedEncodingException; import java.util.Collection; +import net.pterodactylus.util.crypto.MessageDigestHasher; +import net.pterodactylus.util.number.Hex; import net.pterodactylus.util.object.Default; /** @@ -59,6 +62,57 @@ public class DefaultUser extends DefaultBase implements User { * {@inheritDoc} */ @Override + public User setPassword(String password) { + try { + getValue("password", String.class).set(Hex.toHex(MessageDigestHasher.getSHA256Hasher().hash(password.getBytes("UTF-8")))); + return this; + } catch (UnsupportedEncodingException uee1) { + throw new RuntimeException("VM does not support UTF-8.", uee1); + } + } + + /** + * {@inheritDoc} + */ + @Override + public User setPasswordHash(String passwordHash) { + getValue("password", String.class).set(passwordHash); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean verifyPassword(String password) { + try { + return getValue("password", String.class).get().equalsIgnoreCase(Hex.toHex(MessageDigestHasher.getSHA256Hasher().hash(password.getBytes("UTF-8")))); + } catch (UnsupportedEncodingException uee1) { + throw new RuntimeException("VM does not support UTF-8.", uee1); + } + } + + /** + * {@inheritDoc} + */ + @Override + public int getLevel() { + return Default.forNull(getValue("level", Integer.class).get(), 0); + } + + /** + * {@inheritDoc} + */ + @Override + public User setLevel(int level) { + getValue("level", Integer.class).set(level); + return this; + } + + /** + * {@inheritDoc} + */ + @Override @SuppressWarnings("unchecked") public Collection getOpenIds() { return getValue("openIds", Collection.class).get();