1

I'm trying to hash my passwords for login on my Ionic 3 app. I found some tutorial about jsencrypt but it doesn't work and i don't really understand how it work...

Here what i did :

npm install --save jsencrypt

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ApiDatabaseService } from '../../providers/api-database-service';
import Encrypt from 'jsencrypt';
import { Injectable } from '@angular/core';

@Component({
  selector: 'page-Login',
  templateUrl: 'Login.html'
})

@Injectable()

export class LoginPage {

  private prem: string = `my_key`;
  Users:any = []; // Here there is all my users 

  constructor(public navCtrl: NavController, public serviceOne: ApiDatabaseService) {
    this.serviceOne.getDataUser().subscribe( // I'm calling my api to acces to my database
            data => this.Users = data
        );
  }

  public create(name: string): string { // Here the password should be encrypt
        let encrypt = new Encrypt.JSEncrypt();
        encrypt.setPublicKey(this.pem);
        return encrypt.encrypt(name);
    };
}

And i have this error :

Typescript Error Property 'pem' does not exist on type 'LoginPage'.

Also, for Ionic 2 there is many documentation like this : https://docs.ionic.io/services/auth/. But nothing for Ionic 3, why ?

TuxxyDOS
  • 195
  • 3
  • 17

4 Answers4

2

Change the line

encrypt.setPublicKey(this.pem);

To

encrypt.setPublicKey(this.prem);
1

When using the Ionic service your app sends your plain password to the Ionic with service when creating and logging into your account. The auth service will handling all the encryption.

Also, there are no separate docs for Ionic 3 as it is essential the same as Ionic 2 except for some new features and big fixes. There are a few breaking changes but not many. It's not a full rewrite like there was going from Ionic 1 -> Ionic 2 and they are now using semantic versioning so major releases will be more regular similar to Angular.

Jack Vial
  • 2,354
  • 1
  • 28
  • 30
1

change

private prem: string = `my_key`;

to

`private pre: string = `my_key`;
Grenoblois
  • 503
  • 1
  • 5
  • 19
1

change the line

private prem: string = `my_key`;

to

private pem: string = `my_key`;
Siundu254
  • 41
  • 4